早教吧 育儿知识 作业答案 考试题库 百科 知识分享

为什么ACM-ICPC通过不了?DescriptionMaybethereare750,000wordsinEnglishandsomewordsareprefixofotherwords,forexample:theword"acm"canbetreatasoneprefixof"acmicpc".What'smore,mostofsuchpairsofwordshaverelationshipbe

题目详情
为什么ACM-ICPC通过不了?
Description
Maybe there are 750,000 words in English and some words are prefix of other words,for example:the word "acm" can be treat as one prefix of "acmicpc".What's more,most of such pairs of words have relationship between them.Now give you a dictionary,your work is to tell me how many such pairs.
There may be other characters in the word,for example '_','-',and so on.
Pay attention that 'A' and 'a' are not the same character!
Input
In the first line of the input file there is an Integer T,which means the number of test cases.Followed by T test cases.
For each test case,in the first line there is an integer N(0next = NULL;
p = head;
while(p!=NULL) {
s = p->next;
while(s!=NULL) {
flag = 1;
t = 0;
while(p->ch[t]!='\0'&&s->ch[t]!='\0') {
if(p->ch[t]!=s->ch[t]) {
flag = 0;
break;
}
t++;
}
if(flag) k++;
s = s->next;
}
p = p->next;
}
if(k>11519) {
*(l+j) = k%11519;
}
else *(l+j) = k;
}
for(i=0;i































▼优质解答
答案和解析
不知道ACM是否会对时间复杂度和空间复杂度有要求,我觉得你的程序是没错,也没曲解题意,但是算法效率实在不敢恭维.或许是测试时输入了大量的数据,结果你的程序超时或者内存溢出了