Source code for submission s1009

bugs.cpp

  1. #include <cstdio>
  2. #include <cstring>
  3. using namespace std;
  4.  
  5. #define NULLCHAR 2
  6.  
  7. inline bool match_delete(const int index, const int B_len, const char B[], char LINE[]){
  8. int b=0, l = index;
  9. while (b < B_len){
  10. while (LINE[l] == NULLCHAR){
  11. l++;
  12. }
  13.  
  14. if(B[b] != LINE[l]){
  15. return false;
  16. }
  17.  
  18. b++;
  19. l++;
  20. }
  21.  
  22. for (int i = index; i < l; i++){
  23. LINE[i] = NULLCHAR;
  24. }
  25. return true;
  26. }
  27.  
  28. int main()
  29. {
  30. int N;
  31. char B[1010];
  32. char LINE[2000010];
  33. while (scanf("%d %1005s", &N, B) == 2) {
  34. gets(LINE);
  35. int B_len = strlen(B);
  36. for (int row = 0; row < N; row++) {
  37. gets(LINE);
  38. int index = 0;
  39. while (LINE[index] != '\0') {
  40. if (LINE[index] == B[0]){
  41. if (match_delete(index, B_len, B, LINE)){
  42. index -= B_len;
  43. if (index < 0){
  44. index = 0;
  45. }
  46. }
  47. }
  48. index++;
  49. }
  50. index = 0;
  51. while (LINE[index] != '\0'){
  52. if (LINE[index] != NULLCHAR){
  53. printf("%c", LINE[index]);
  54. }
  55. index++;
  56. }
  57. printf("\n");
  58. }
  59. }
  60. return 0;
  61. }
  62.