Description
S公司在招聘新的人才,由于S公司是个大公司,所以来应聘的人非常多。这可难坏了我们的小Q小姐,因为有个人交了两份申请表,这样不得不让小Q每次得看两回申请表,现在小Q小姐想统计出来有多少人交了两份申请表。
现在我们来简化这个问题,对于该问题有两个字符窜是s1和s2,每个字符窜都包含许多人的名字,不同人的名字用空格隔开,现在让你统计s1和s2,出现相同人名字的个数是多少。
例如s1=“Alice Bob Jame”
s2=“Bob MINA”
则答案是1,因为两窜人名相同的是Bob
Input
输入首先包含一个正整数T,表示有T组测试样例;
然后分别输入字符窜s1和s2(len<100),每个字符窜包含许多个人的名字,名字和名字之间用空格隔开
可以保证每个人名在每个字符窜中仅仅出现一次
Output
对于每组测试数据,用一行输出一个ans,表示有多少个人名字在两窜中都出现了
Sample Input
2 Alice Bob Jame Bob MINA a b c d a b c d
Sample Output
1 4
解题思路:水题,将一串字符串按照空格拆分成一个个的单词作为名字,进行名字匹配,只需要遍历两个存储名字的二维数组即可,然而我还是wa了好
几发,原因是没有想到名字之间可能间隔了不止一个空格。
上代码:
1 #include<stdio.h> 2 #include<string.h> 3 int main() 4 { 5 int n,i,j,k,u,z,m,len1,len2,count; 6 char a[110],b[110]; 7 char x[110][110]={0},s[110][110]={0}; 8 scanf("%d",&n); 9 getchar(); 10 while(n--) 11 { 12 gets(a); 13 gets(b); 14 len1=strlen(a); 15 len2=strlen(b); 16 k=0,j=0; 17 for(i=0; i<=len1; i++) 18 { 19 if(a[i]!=' '&&a[i]!='