传话游戏 2013编程之美

编程入门 行业动态 更新时间:2024-10-24 11:25:46

传话游戏 2013编程<a href=https://www.elefans.com/category/jswz/34/1764446.html style=之美"/>

传话游戏 2013编程之美

 我写了一个答案,在我的编译器是可以通过的,提交之后给出runtime error.甚是费解,求那个高人,大婶,帮忙看看

 

 
  1. //author bruce 
  2. //2013/4/17 
  3. #include <string>  
  4. #include <iostream> 
  5. #include <map> 
  6. #include <cstdio>  
  7. #include <cstring>  
  8. #include <cmath>  
  9. using namespace std; 
  10.  
  11. map<string,string> WORDS;  
  12. char a_word[20],b_word[20]; //字符长度限制 
  13. char Total_words[100];  //alice说的话 
  14. char    *p; 
  15. int  T,M,N;//分别表示组数,转换列表长度,以及参赛的人数 
  16. char *d=" ";//delim  
  17. void passMessage(); 
  18. int main()  
  19. {  
  20.     cout<<"请输入测试数据组数"<<endl; 
  21.     scanf("%d%*c",&T); 
  22.     for(int NM_NUM = 1;NM_NUM <= T;NM_NUM++)  
  23.     { 
  24.         WORDS.clear();  
  25.         cout<<"请分别输入参赛人数和列表长度(注意 人数一定要大于1人,否则传话又有什么意思呢)"<<endl; 
  26.         scanf("%d %d%*c",&N,&M); 
  27.          
  28.  
  29.         for(int  i = M;i > 0;i--) 
  30.         {  
  31.             cout<<"请分别输入转换前单词a,和转换后单词b"<<endl; 
  32.             scanf("%s %s%*c",a_word,b_word);  
  33.             WORDS[a_word] = b_word;  
  34.         } 
  35.         cout<<"请输入alice想说的话"<<endl; 
  36.         gets(Total_words); 
  37.         p = strtok(Total_words,d); 
  38.         printf("传话完毕之后 Case #%d:\n ",NM_NUM); 
  39.         //cout<<"传话完毕之后"<<endl; 
  40.         passMessage(); 
  41.          
  42.         while(  p=strtok(NULL,d)  ) 
  43.         { 
  44.              
  45.             cout<<""; 
  46.             passMessage();  
  47.         }  
  48.         cout<<endl; 
  49.     } 
  50.     return 0;  
  51. }  
  52. void passMessage()  
  53. {  
  54.     string messageWords; 
  55.     messageWords = p;  
  56.     bool judge; 
  57.     for(int i = 1;i < N;i++) 
  58.     {  
  59.         judge = WORDS.count(messageWords); 
  60.         if(judge) messageWords = WORDS[messageWords];  
  61.         else  
  62.             break; 
  63.     }  
  64.     cout<<messageWords<<endl;  
  65. }  

本文出自 “LuoZhengWu” 博客,请务必保留此出处

更多推荐

传话游戏 2013编程之美

本文发布于:2024-02-10 23:05:25,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1677805.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:之美   游戏

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!