Source code for submission s1325

Go to diff to previous submission

bugs.cpp

  1. #include <iostream>
  2. #include <stdio.h>
  3. #include <string.h>
  4.  
  5.  
  6. using namespace std;
  7.  
  8. int main ( int argc, char * argv [] )
  9. {
  10. int linesCount;
  11. unsigned int equal;
  12. unsigned int j, k;
  13. string bug;
  14.  
  15.  
  16.  
  17. char *input = new char [2000000];
  18. bool finish = false;
  19. int z = 0;
  20.  
  21.  
  22. while ( cin >> linesCount >> bug ) {
  23.  
  24. z = 0;
  25. while( z < linesCount + 1 )
  26. {
  27.  
  28. gets(input);
  29.  
  30. for ( unsigned int i = 0; i < strlen( input ); i ++ ) {
  31.  
  32. if ( input[ i ] != bug[ 0 ] ) {
  33. cout << input[ i ];
  34. continue;
  35. }
  36.  
  37. equal = 0;
  38.  
  39. for ( j = 0; j < bug.length(); j ++ ) {
  40.  
  41. if ( i + j > strlen( input ) && j < bug.length() ){
  42. finish = true;
  43. break;
  44. }
  45.  
  46. if ( input[ i + j ] == bug[ j ] )
  47. equal ++;
  48.  
  49. }
  50.  
  51. if ( finish ) {
  52. for ( unsigned x = i; x < strlen( input ); x ++ )
  53. cout << input[ x ];
  54. }
  55.  
  56.  
  57. if ( equal == bug.length() ){
  58. i += bug.length() - 1;
  59. continue;
  60. }
  61.  
  62. for ( k = i; k < i + equal ; k ++ )
  63. cout << input[ k ];
  64. i = i + equal - 1;
  65.  
  66. }
  67. z++;}
  68. }
  69.  
  70.  
  71. delete [] input;
  72.  
  73. return 0;
  74. }
  75.  

Diff to submission s1300

bugs.cpp

--- 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;