Advertisement
LA77

Untitled

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