Cod sursa(job #721139)

Utilizator thesilverhand13FII Florea Toma Eduard thesilverhand13 Data 23 martie 2012 12:48:08
Problema Potrivirea sirurilor Scor 40
Compilator cpp Status done
Runda Arhiva educationala Marime 0.82 kb
 # include <fstream>
 # include <cstring>
 
 # define dim 2000005
 
 using namespace std;
 
 ifstream f("strmatch.in");
 ofstream g("strmatch.out");
 
 char a[ dim ], b[ dim ];
 int poz[ dim ];
 int lga, lgb;
 
 void citire()
 {
	 f.getline( a, dim );
	 f.getline( b, dim );
	 lga = strlen( a );
	 lgb = strlen( b );
 }
 
 void rezolva()
 {
	 int i, j, ok = 1, nr = 0;
	 for ( i = 0 ; i < lgb ; i++ )
	 {
		 ok = 0;
		 if ( b[ i ] == a[ 0 ] )
			 ok = 1;
		 for ( j = 0 ; j < lga && ok == 1 ; j++ )
			 if ( a[ j ] != b[ i + j ] )
				 ok = 0;
			 if ( ok == 1 )
			 {
				 nr++;
				  poz[ 0 ]  ++;
				 poz[ poz[ 0 ] ] = i;
			 }
			 
	 }
	 g << nr;
	 g << "\n";
	 for ( i = 1 ; i <= poz[ 0 ] ; i++ )
		 g << poz[ i ] << " ";
 }
 
 int main()
 {
	 citire();
	 rezolva();
	 return 0;
 }