Advertisement
a53

masca

a53
Feb 28th, 2019
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.28 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. ifstream fin("masca.in");
  4. ofstream fout("masca.out");
  5. char mask[105], s[105], a[1005][105];
  6. int n, i, j, k, p, la, nrcd;
  7. bool ok;
  8.  
  9. bool match(char *first, char * second)
  10. {
  11. if (*first == '\0' && *second == '\0')
  12. return true;
  13. if(*first == '?' && *second == '\0')
  14. return false;
  15. if (*first == '*' && *(first+1) != '\0' && *second == '\0')
  16. return false;
  17. if (*first == '?' || *first == *second)
  18. return match(first+1, second+1);
  19. if (*first == '*')
  20. return match(first+1, second) || match(first, second+1);
  21. return false;
  22. }
  23.  
  24. int main()
  25. {
  26. fin>>p;
  27. fin.get();
  28. fin.getline(mask,105);
  29. fin>>n;
  30. fin.get();
  31. for(i=1;i<=n;i++)
  32. {
  33. fin.getline(s,105);
  34. if(i==1)
  35. strcpy(a[la++],s);
  36. else
  37. {
  38. ok=0;
  39. for(j=0;j<la && !ok;j++)
  40. if(strcmp(s,a[j])==0)
  41. ok=1;
  42. if(ok==0)
  43. strcpy(a[la++],s);
  44. }
  45. }
  46. if(p==1)
  47. fout<<la<<'\n';
  48. else
  49. {
  50. for(i=0;i<la;i++)
  51. {
  52. ok=match(mask,a[i]);
  53. if(ok)
  54. nrcd++;
  55. }
  56. fout<<nrcd;
  57. }
  58. return 0;
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement