原题:
Description
I guess most of us are so called 80ers, which means that we were born in the 1980's. This group of people shared a lot of common memories. For example, the Saint Seiya, the YoYo ball, the Super Mario, and so on. Do you still remember these?
Input
There will be ONLY ONE test case.
The test case begins with a positive integer N, (N < 100).
Then there will be N lines each containing a single word describing a keyword of the typical 80ers' memories. Each word consists of letters, [a-zA-Z], numbers, [0-9], and the underline, '_'. The length of each word would be no more than 20.
Then one line follows with a positive integer K, (K < 100).
The last part of the test case will be K lines. The i-th line contains the keywords given by thei-th person and starts with a positive integer Ni. Then there will beNi words separated by white spaces. Each of these words has no more than 20 characters.
All the words are case sensitive.
Output
For each of these K people, you are asked to count the number of typical 80ers' keywords on his/her list and output it in a single line.
Sample Input
4 Saint_Seiya YoYo_ball Super_Mario HuLuWa 3 2 Saint_Seiya TiaoFangZi 1 ××× 3 HuLuWa YOYO_BALL YoYo_ball
Sample Output
1 0 2
分析:
感觉这道题也挺顺手,只不过得提高速度。。。
原码:
#include<stdio.h> #include<string.h> int main() { char k[101][22]; int c,num,i; int n,p; char str[22]; scanf("%d",&n); for(i=0; i<n; i++) scanf("%s",k[i]); scanf("%d",&p); while(p--) { c = 0; scanf("%d",&num); while(num--) { scanf("%s",str); for(i=0; i<n; i++) if( strcmp(str,k[i]) == 0) c++; } printf("%d\n",c); } return 0; }