Source code for submission s1291

bug.c

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. int solve(char bug[1000], unsigned int bugsz)
  5. {
  6. /* printf("%s %u\n", bug, bugsz);
  7. */
  8. char *line = malloc(2000001);
  9.  
  10. char c = ' ';
  11. int off = 0;
  12.  
  13. while ((c != 0) && (c!= '\n')) {
  14. c = getchar();
  15. line[off] = c;
  16. off++;
  17. }
  18. line[off] = 0;
  19.  
  20. off = strlen(line);
  21.  
  22. int i;
  23. for (i = 0; i < off; i++) {
  24. if (!strncmp(&line[i], bug, bugsz)) {
  25.  
  26. i+= bugsz-1;
  27. } else {
  28. putchar(line[i]);
  29. }
  30. }
  31.  
  32. free(line);
  33. }
  34.  
  35. int main(void)
  36.  
  37. {
  38.  
  39.  
  40.  
  41.  
  42. while(1){
  43.  
  44.  
  45.  
  46.  
  47. char bug[1001] = {0};
  48. int n = 2000000000;
  49.  
  50.  
  51. scanf("%u %s", &n, bug);
  52.  
  53.  
  54. if (n == 2000000000) return 0;
  55.  
  56. int i;
  57. for (i = 0; i < n; i++) {
  58.  
  59. solve(bug, strlen(bug));
  60.  
  61. }
  62.  
  63.  
  64. }
  65.  
  66.  
  67.  
  68.  
  69.  
  70.  
  71.  
  72.  
  73.  
  74.  
  75.  
  76.  
  77.  
  78.  
  79.  
  80.  
  81.  
  82. }
  83.