Source code for submission s1101

Go to diff to previous submission

bugs.cpp

  1. //
  2. // File: bugs.cc
  3. // Author: cteam049
  4. //
  5. // Created on October 27, 2012, 12:03 PM
  6. //
  7.  
  8. #include <stdlib.h>
  9. #include <stdio.h>
  10. #include <string.h>
  11. #include <iostream>
  12.  
  13. using namespace std;
  14.  
  15. //
  16. //
  17. //
  18.  
  19. bool findBug(int index, int lineLength, char* line, char* replacement, int replLength){
  20. for(int i = index; i - index < replLength ; i++) {
  21. if(i >= lineLength) return false;
  22. if(line[i] != replacement[i - index]) return false;
  23. }
  24. //cout << "bug nalezen" << endl;
  25. return true;
  26. }
  27.  
  28. int main(int argc, char** argv) {
  29. int lines, len, pos, lineLength = 2000002, tmpLength = 2000002, replLength = 1001;
  30. // char line[2000002];
  31. // char lineTmp[2000002];
  32. char* line = new char[2000002];
  33. char* lineTmp = new char[2000002];
  34. char replacement[1001];
  35. char tmp;
  36. bool found;
  37.  
  38. while(1){
  39. if(scanf("%d", &lines) != 1) break;
  40. if(scanf(" %s", &replacement) != 1) break;
  41. //precti cislo
  42. //scanf("%d %s", &lines, &replacement);
  43. replLength = strlen(replacement);
  44. getchar();
  45.  
  46. // cout << "\nlines je " << lines << endl;
  47. // cout << "replacement je " << replacement << endl;
  48. // cout << "delka replacementu je " << replLength << endl;
  49.  
  50. for(int i = 0; i < lines; i++) {
  51. tmpLength = 0;
  52. lineLength = 0;
  53. //nacti radek
  54. do {
  55. tmp = getchar();
  56. lineTmp[tmpLength] = tmp;
  57. tmpLength++;
  58. } while (tmp != '\n');
  59. // cout << "delka radku je " << tmpLength << endl;
  60.  
  61. found = true;
  62. //ted je radek nacten
  63. while(found) {
  64. found = false;
  65. lineLength = 0;
  66.  
  67. for(int j = 0; j < tmpLength; j++) {
  68. //hledame vyskyty bugu
  69. if(findBug(j, tmpLength, lineTmp, replacement, replLength)){
  70. j+= replLength - 1;
  71. found = true;
  72. }
  73. else {
  74. line[lineLength] = lineTmp[j];
  75. lineLength++;
  76. }
  77. //cout << "i je " << i << endl;
  78.  
  79.  
  80. }
  81. // cout << "radek po pruchodu: " << endl;
  82. // bugs.cc:100: error: expected unqualified-id before 'return' for(int i = 0; i < lineLength; i++) {
  83. // cout << line[i];
  84. // }
  85. // cout << endl;
  86.  
  87.  
  88. //for(int j = 0; j < lineLength; j++) {
  89. //lineTmp[j] = line[j];
  90.  
  91. // }
  92. lineTmp = line;
  93. tmpLength = lineLength;
  94. }
  95. for(int k = 0; k < lineLength; k++) {
  96. //cout << line[k];
  97. putchar(line[k]);
  98. }
  99. //cout << endl;
  100. }
  101. //getchar();
  102. }
  103. //delete line;
  104. //delete lineTmp;
  105. return 0;
  106. }
  107.  
  108.  

Diff to submission s1088

bugs.cpp

--- c4.s1088.cteam049.bugs.cpp.0.bugs.cpp
+++ c4.s1101.cteam049.bugs.cpp.0.bugs.cpp
@@ -28,6 +28,8 @@
 int main(int argc, char** argv) {
     int lines, len, pos, lineLength = 2000002, tmpLength = 2000002, replLength = 1001;
-    char line[2000002];
-    char lineTmp[2000002];
+//    char line[2000002];
+//    char lineTmp[2000002];
+    char* line = new char[2000002];
+    char* lineTmp = new char[2000002];
     char replacement[1001];
     char tmp;
@@ -84,7 +86,9 @@
                 
                 
-                for(int j = 0; j < lineLength; j++) {
-                    lineTmp[j] = line[j];
-                }
+                //for(int j = 0; j < lineLength; j++) {
+                    //lineTmp[j] = line[j];
+                    
+               // }
+                lineTmp = line;
                 tmpLength = lineLength;
             }
@@ -95,5 +99,8 @@
             //cout << endl;
         }
+        //getchar();
     }
+    //delete line;
+    //delete lineTmp;
     return 0;
 }