Problem Description
Problem Analysis
The idea is to compare the lengths of the two strings first
Only when the lengths are equal is it necessary to check whether they match
When they are equal
just compare them one by one
ignoring the case where the character == ‘’
(I used another char array to record the indices of ‘’ — seems it wasn’t necessary at all -.-)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
| #include<stdio.h>
#include<string.h>
int main() {
char s[120];
char v[120];
int a[120];
int T,n,l,lv,sum;
int i;
scanf("%d",&T);
getchar();
while(T--) {
gets(s);
memset(a,0,sizeof(a));
l=strlen(s);
for(i=sum=0; i<l; i++) {
if(s[i]=='*')
a[i]=1;
}
scanf("%d",&n);
getchar();
while(n--) {
gets(v);
lv=strlen(v);
if(lv==l) {
for(i=0; i<l; i++) {
if(!a[i]&&s[i]!=v[i]) {
break;
}
}
if(i>=l)
sum++;
} else
continue;
}
printf("%d\n",sum);
}
return 0;
}
|
Problem link: ZZULI 1804 ZY Senior’s Password