Source code for submission s753

bugs.cpp

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string>
  4. #include <iostream>
  5.  
  6. using namespace std;
  7.  
  8. void analyseLine ( string & text, string & line )
  9. {
  10. string::size_type lastPos = 0;
  11. if ( !line.length() )
  12. {
  13. cout << endl;
  14. return;
  15. }
  16. while ( 1 )
  17. {
  18. lastPos = line.find ( text, lastPos );
  19. if ( lastPos == string::npos )
  20. {
  21. //cout << lastPos << " " << string::npos << endl;
  22. break;
  23. }
  24. line = line.erase ( lastPos, text.length() );
  25. //cout << "PO ERASU:" << line << " pos:" << lastPos << endl;
  26. lastPos = ( lastPos - text.length() + 1 < 0 ) || ( lastPos - text.length() + 1 > 2500000 ) ? 0 : lastPos - text.length() + 1;
  27. //cout << lastPos << endl;
  28. }
  29. cout << line << endl;
  30. }
  31.  
  32. int main ( void )
  33. {
  34. int n, i;
  35. char bug[1010];
  36. char tmp;
  37. string line;
  38. string text;
  39.  
  40. while ( scanf ( "%d %s%c", &n, bug, &tmp ) == 3 )
  41. {
  42. text = string ( bug );
  43. for ( i = 0; i < n; i++ )
  44. {
  45. getline ( cin, line );
  46. analyseLine ( text, line );
  47. }
  48. }
  49. return 0;
  50. }
  51.