Advertisement
LA77

Untitled

Oct 8th, 2024
19
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.37 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <string.h>
  3.  
  4. char s[1000001];
  5. int n, ms;
  6. char line[1000001];
  7.  
  8. int main()
  9. {
  10. scanf("%s", s);
  11. scanf("%d", &n);
  12. char temp;
  13. scanf("%c", &temp);
  14.  
  15. while(n--)
  16. {
  17. fgets(line, sizeof(line), stdin);
  18.  
  19. int ir;
  20. for(int i = 0; i < strlen(line); ++i)
  21. {
  22. if(line[i] == ':')
  23. {
  24. ir = i + 1;
  25. break;
  26. }
  27. }
  28.  
  29. int match = -1;
  30.  
  31. for(int i = ir; i < strlen(line) - strlen(s); ++ i)
  32. {
  33. int cnt = 0;
  34. for(int j = 0; j < strlen(s); ++ j)
  35. {
  36. if(line[i + j] == s[j])
  37. {
  38. cnt++;
  39. }
  40. else
  41. {
  42. break;
  43. }
  44. }
  45. if(cnt == strlen(s))
  46. {
  47. match = i - ir;
  48. break;
  49. }
  50. }
  51.  
  52. if(match != -1)
  53. {
  54. for(int i = 0; i < ir - 1; i ++)
  55. {
  56. printf("%c", line[i]);
  57. }
  58. printf(": shift=%d\n", match);
  59. ms++;
  60. }
  61. }
  62.  
  63. if(ms == 1)
  64. {
  65. printf("%d match found.\n", ms);
  66. }
  67. else
  68. {
  69. printf("%d matches found.\n", ms);
  70. }
  71. return 0;
  72. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement