Source code for submission s1328

bugs.cpp

  1. #include <cstdio>
  2. #include <iostream>
  3. #include <string>
  4.  
  5. using namespace std;
  6.  
  7. int main (void)
  8. {
  9. string bug_str;
  10. string line_str;
  11.  
  12. string s;
  13.  
  14. int lines;
  15. unsigned int pozice;
  16. int start;
  17. int bug_len;
  18.  
  19. while(scanf("%d", &lines) == 1) {
  20. getline(cin,bug_str);
  21. bug_str.erase(0,1);
  22. bug_len = bug_str.length();
  23.  
  24. for (int i = 0; i < lines; i++) {
  25. s = "";
  26. getline(cin, line_str);
  27. s.append(line_str);
  28.  
  29. start = 0;
  30. pozice = s.find(bug_str);
  31. if (pozice == string::npos) {
  32. cout << s << endl;
  33. }
  34. else {
  35. start = pozice;
  36. s.erase(start, bug_len);
  37.  
  38. while (1) {
  39. pozice = s.find(bug_str,start);
  40. if (pozice == string::npos) break;
  41.  
  42. start = pozice;
  43. s.erase(start, bug_len);
  44. }
  45.  
  46. cout << s << endl;
  47. }
  48. }
  49. }
  50. return 0;
  51. }
  52.