Source code for submission s1307

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, tmpLength, replLength;
  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. //nacti radek
  53. do {
  54. tmp = getchar();
  55. lineTmp[tmpLength] = tmp;
  56. tmpLength++;
  57. } while (tmp != '\n');
  58. // cout << "delka radku je " << tmpLength << endl;
  59.  
  60. found = true;
  61. //ted je radek nacten
  62. while(found) {
  63. found = false;
  64. lineLength = 0;
  65.  
  66. for(int j = 0; j < tmpLength; j++) {
  67. //hledame vyskyty bugu
  68. if(findBug(j, tmpLength, lineTmp, replacement, replLength)){
  69. j+= replLength - 1;
  70. found = true;
  71. }
  72. else {
  73. line[lineLength] = lineTmp[j];
  74. lineLength++;
  75. }
  76. //cout << "i je " << i << endl;
  77.  
  78.  
  79. }
  80. // cout << "radek po pruchodu: " << endl;
  81. // bugs.cc:100: error: expected unqualified-id before 'return' for(int i = 0; i < lineLength; i++) {
  82. // cout << line[i];
  83. // }
  84. // cout << endl;
  85.  
  86.  
  87. //for(int j = 0; j < lineLength; j++) {
  88. //lineTmp[j] = line[j];
  89.  
  90. // }
  91. lineTmp = line;
  92. tmpLength = lineLength;
  93. }
  94. for(int k = 0; k < lineLength; k++) {
  95. //cout << line[k];
  96. putchar(line[k]);
  97. }
  98. //cout << endl;
  99. }
  100. //getchar();
  101. }
  102. //delete line;
  103. //delete lineTmp;
  104. return 0;
  105. }
  106.  
  107.  

Diff to submission s1101

bugs.cpp

--- c4.s1101.cteam049.bugs.cpp.0.bugs.cpp
+++ c4.s1307.cteam049.bugs.cpp.0.bugs.cpp
@@ -27,5 +27,5 @@
 
 int main(int argc, char** argv) {
-    int lines, len, pos, lineLength = 2000002, tmpLength = 2000002, replLength = 1001;
+    int lines, len, pos, lineLength, tmpLength, replLength;
 //    char line[2000002];
 //    char lineTmp[2000002];
@@ -50,5 +50,4 @@
         for(int i = 0; i < lines; i++) {
             tmpLength = 0;
-            lineLength = 0;
             //nacti radek
             do {