Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- ifstream fin("masca.in");
- ofstream fout("masca.out");
- char mask[105], s[105], a[1005][105];
- int n, i, j, k, p, la, nrcd;
- bool ok;
- bool match(char *first, char * second)
- {
- if (*first == '\0' && *second == '\0')
- return true;
- if(*first == '?' && *second == '\0')
- return false;
- if (*first == '*' && *(first+1) != '\0' && *second == '\0')
- return false;
- if (*first == '?' || *first == *second)
- return match(first+1, second+1);
- if (*first == '*')
- return match(first+1, second) || match(first, second+1);
- return false;
- }
- int main()
- {
- fin>>p;
- fin.get();
- fin.getline(mask,105);
- fin>>n;
- fin.get();
- for(i=1;i<=n;i++)
- {
- fin.getline(s,105);
- if(i==1)
- strcpy(a[la++],s);
- else
- {
- ok=0;
- for(j=0;j<la && !ok;j++)
- if(strcmp(s,a[j])==0)
- ok=1;
- if(ok==0)
- strcpy(a[la++],s);
- }
- }
- if(p==1)
- fout<<la<<'\n';
- else
- {
- for(i=0;i<la;i++)
- {
- ok=match(mask,a[i]);
- if(ok)
- nrcd++;
- }
- fout<<nrcd;
- }
- return 0;
- }
Add Comment
Please, Sign In to add comment