我写了一个答案,在我的编译器是可以通过的,提交之后给出runtime error.甚是费解,求那个高人,大婶,帮忙看看
- //author bruce
- //2013/4/17
- #include <string>
- #include <iostream>
- #include <map>
- #include <cstdio>
- #include <cstring>
- #include <cmath>
- using namespace std;
- map<string,string> WORDS;
- char a_word[20],b_word[20]; //字符长度限制
- char Total_words[100]; //alice说的话
- char *p;
- int T,M,N;//分别表示组数,转换列表长度,以及参赛的人数
- char *d=" ";//delim
- void passMessage();
- int main()
- {
- cout<<"请输入测试数据组数"<<endl;
- scanf("%d%*c",&T);
- for(int NM_NUM = 1;NM_NUM <= T;NM_NUM++)
- {
- WORDS.clear();
- cout<<"请分别输入参赛人数和列表长度(注意 人数一定要大于1人,否则传话又有什么意思呢)"<<endl;
- scanf("%d %d%*c",&N,&M);
- for(int i = M;i > 0;i--)
- {
- cout<<"请分别输入转换前单词a,和转换后单词b"<<endl;
- scanf("%s %s%*c",a_word,b_word);
- WORDS[a_word] = b_word;
- }
- cout<<"请输入alice想说的话"<<endl;
- gets(Total_words);
- p = strtok(Total_words,d);
- printf("传话完毕之后 Case #%d:\n ",NM_NUM);
- //cout<<"传话完毕之后"<<endl;
- passMessage();
- while( p=strtok(NULL,d) )
- {
- cout<<"";
- passMessage();
- }
- cout<<endl;
- }
- return 0;
- }
- void passMessage()
- {
- string messageWords;
- messageWords = p;
- bool judge;
- for(int i = 1;i < N;i++)
- {
- judge = WORDS.count(messageWords);
- if(judge) messageWords = WORDS[messageWords];
- else
- break;
- }
- cout<<messageWords<<endl;
- }