哪位好心人教下我这道题Time Limit Exceed怎么改进TAT
2437: English wordTime Limit: 1 Sec Memory Limit: 64 MB
Submit: 2362 Solved: 1137
Description
You still are worried about reading acm English problem, let me tell you a kind of very good method of Memorising Words, the root memory method,.the most interesting of the method is the prefix root. Now there are some English words to remembeand he knows some prefix root;He want to know how many words that can be remembered using each the prefix .in other words,how many words that contain the prefix ,Now to acmer you for help, can you help him?
Input
The input consists of T test cases. The number of them (T) is given on the first line of the input file. Each test case begins with a line containing a single integer number N that indicates the number of words (1 <= N <= 10000). Then exactly N lines follow, each containing a single word. Each word contains at least two and at most 10 lowercase characters, that means only letters 'a' through 'z' will appear in the word. The same word may appear several times in the list. Then follow a line containing a single integer number M that indicates the number of Words prefix question (0 <= M<= 10000). Then exactly M lines follow, each containing a single Words prefix.
Output
For the given input data, output exact M line, each line contain a ingle integer indicates the answer of each query.
Sample Input
1
4
preview
predict
premier
press
3
pre
press
pree
Sample Output
4
1
0
我的代码:
#include<stdio.h>
#include<string.h>
int main()
{
int T,N,M,i,j,k,count,flag,e;
char a[10000][10],b[10000][10];
int c[10000];
scanf("%d",&T);
getchar();
scanf("%d",&N);
getchar();
for(e=1;e<=T;e++)
{
for(i=0;i<=N-1;i++)
{
gets(a[i]);
}
scanf("%d",&M);
getchar();
for(i=0;i<=M-1;i++)
{
gets(b[i]);
c[i]=strlen(b[i]);
}
for(i=0;i<=M-1;i++)//na b[1],b[2]...
{
count=0;
for(k=0;k<=N-1;k++)
{
for(j=0;j<=c[i]-1;j++)
{
flag=0;
if(b[i][j]!=a[k][j])
{flag=1;break;}
}
if(flag==0)
{count++;}
}
printf("%d\n",count);
}
}
return 0;
}
跪谢啦~~