Go to diff to previous submission
#include <iostream> #include <stdio.h> #include <string.h> using namespace std; int main ( int argc, char * argv [] ) { int linesCount; unsigned int equal; unsigned int j, k; string bug; char *input = new char [2000000]; bool finish = false; int z = 0; while ( cin >> linesCount >> bug ) { z = 0; while( z < linesCount + 1 ) { gets(input); for ( unsigned int i = 0; i < strlen( input ); i ++ ) { if ( input[ i ] != bug[ 0 ] ) { cout << input[ i ]; continue; } equal = 0; for ( j = 0; j < bug.length(); j ++ ) { if ( i + j > strlen( input ) && j < bug.length() ){ finish = true; break; } if ( input[ i + j ] == bug[ j ] ) equal ++; } if ( finish ) { for ( unsigned x = i; x < strlen( input ); x ++ ) cout << input[ x ]; } if ( equal == bug.length() ){ i += bug.length() - 1; continue; } for ( k = i; k < i + equal ; k ++ ) cout << input[ k ]; i = i + equal - 1; } z++;} } delete [] input; return 0; }
--- c4.s1300.cteam003.bugs.cpp.0.bugs.cpp +++ c4.s1325.cteam003.bugs.cpp.0.bugs.cpp @@ -1,4 +1,5 @@ #include <iostream> #include <stdio.h> +#include <string.h> @@ -11,8 +12,8 @@ unsigned int j, k; string bug; - string input; - char *str = new char [2000000]; + + char *input = new char [2000000]; bool finish = false; int z = 0; @@ -25,9 +26,7 @@ { - gets(str); - input = str; -//cout << input << endl; + gets(input); - for ( unsigned int i = 0; i < input.length(); i ++ ) { + for ( unsigned int i = 0; i < strlen( input ); i ++ ) { if ( input[ i ] != bug[ 0 ] ) { @@ -40,5 +39,5 @@ for ( j = 0; j < bug.length(); j ++ ) { - if ( i + j > input.length() && j < bug.length() ){ + if ( i + j > strlen( input ) && j < bug.length() ){ finish = true; break; @@ -51,5 +50,5 @@ if ( finish ) { - for ( unsigned x = i; x < input.length(); x ++ ) + for ( unsigned x = i; x < strlen( input ); x ++ ) cout << input[ x ]; } @@ -70,5 +69,5 @@ - delete [] str; + delete [] input; return 0;