Source code for submission s851

Go to diff to previous submission

bugs.cpp

  1. #include <iostream>
  2. #include <algorithm>
  3. #include <string>
  4.  
  5. using namespace std;
  6.  
  7.  
  8.  
  9.  
  10.  
  11. int main(){
  12. int l;
  13. string rep, str;
  14.  
  15. while(1)
  16. {
  17. cin>>l>>rep;
  18. if(!(cin.good())) break;
  19.  
  20. int n=0;
  21. cin.get();
  22. for(int i=0;i<l;i++)
  23. {
  24. getline(cin,str);
  25. n=0;
  26. while(1)
  27. {
  28. n=str.find(rep,n);
  29. if(n==string::npos) break; //string::npos
  30. str.erase(n,rep.length());
  31. n-=rep.length();
  32. //break;
  33. if(n<0)
  34. n=0;
  35.  
  36. }
  37. cout<<str<<endl;
  38. }
  39.  
  40.  
  41.  
  42. }
  43. return 0;
  44. }
  45.  

Diff to submission s849

bugs.cpp

--- c4.s849.cteam042.bugs.cpp.0.bugs.cpp
+++ c4.s851.cteam042.bugs.cpp.0.bugs.cpp
@@ -18,5 +18,5 @@
                 if(!(cin.good())) break;
                 
-                size_t n=0;
+                int n=0;
                 cin.get();
                 for(int i=0;i<l;i++)
@@ -29,7 +29,7 @@
                                 if(n==string::npos) break; //string::npos
                                 str.erase(n,rep.length());
-                                //n-=rep.length();
+                                n-=rep.length();
                                 //break;
-                                //if(n<0) 
+                                if(n<0) 
                                 n=0;