Advertisement
pdaogu

STRINGMATCH

Jun 4th, 2019
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.92 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include <ctype.h>
  5. #define maxn 1000030
  6.  
  7. char p[1000];
  8. char t[2000][5000];
  9. int q = 0, n = 0;
  10.  
  11. void clearBuffer () {
  12.     char c;
  13.     while ((c = getchar()) != '\n' && c != EOF);
  14. }
  15.  
  16. void input () {
  17.     gets(p);
  18.     char tmp[5000];
  19.     gets(tmp);
  20.     while (strcmp(tmp, "#") != 0) {
  21.         strcpy(t[n++], tmp);
  22.         scanf("%[^\n]", tmp);
  23.         clearBuffer();
  24.         printf("%s\n", t[n-1]);
  25.     }
  26. }
  27.  
  28. void output () {
  29.     printf("%d\n", q);
  30. }
  31.  
  32. int countLine (int k) {
  33.     int lenp = strlen(p);
  34.     int lent = strlen(t[k]);
  35.     int occ = 0;
  36.     for (int i = 0; i < lent; ++i) {
  37.         int j = 0;
  38.         int a = i;
  39.         // printf("%c:%c\n", t[k][a], p[j]);
  40.         while ((j < lenp && a < lent) && t[k][a++] == p[j++]) {
  41.         }
  42.         if (j >= lenp)
  43.             ++occ;
  44.     }
  45.     return occ;
  46. }
  47.  
  48. void solve () {
  49.     for (int i = 0; i < n; ++i) {
  50.         q += countLine(i);
  51.     }
  52. }
  53.  
  54. int main () {
  55.     input();
  56.     solve();
  57.     output();
  58.     return 0;
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement