HDU——1075 What Are You Talking About
2014-10-13 22:19
375 查看
题意:首先给你一个英文单词对应Mars文的单词表,接着给你一段话,将里边的Mars文翻译成英文输出。
解题思路:本题首先要解决输入时的格式问题,利用string和get()函数的结合来处理,本题的关键点是将英文单词对应Mars文的单词表用map函数来表示,具体的见代码。
Code:
解题思路:本题首先要解决输入时的格式问题,利用string和get()函数的结合来处理,本题的关键点是将英文单词对应Mars文的单词表用map函数来表示,具体的见代码。
Code:
#include <iostream> #include <cstring> #include <string> #include <cstdio> #include <map> using namespace std; map<string,string> vis; int main() { //freopen("input.txt","r",stdin); string str1,str2; cin>>str1;//先将START接收 while(cin>>str1 && str1 != "END")//然后进入循环接收单词 { cin>>str2; vis[str2] = str1;//英文和Mars映射到map当中 } cin>>str1;//开始翻译句子中的Mars文 getchar();//因为cin不接收回车,而gets()函数接收,故需要加getchar()函数将回车吸收 while(1) { char words[3005]; gets(words);//把句子全部接收下来 if(strcmp(words,"END") == 0) break;//遇见END直接跳出 int len = strlen(words); str2 = ""; for(int i = 0; i < len; i++) { if(words[i] >= 'a' && words[i] <= 'z') { str2 +=words[i]; continue;}//将英文字母累加成字符串 if(words[i] < 'a' || words[i] > 'z')//当遇见不是字母的字符时,表示已经接收了一个单词,然后进行翻译输出 { if(vis[str2] != "") cout<<vis[str2];//是Mars文就输出对应的英文 else cout<<str2;//是英文的直接输出 printf("%c",words[i]);//同时将其他字符也输出 str2 = "";//每次输出一个单词,要将str2置为空 } } printf("\n"); } return 0; }
相关文章推荐
- HDU 1075(What Are You Talking About-Trie的插入和查找)
- HDU 1075 What Are You Talking About // 字符串映射,Trie
- HDU 1075 What Are You Talking About (map解法+Trie解法)
- HDU 1075 What Are You Talking About
- HDU 1075 What Are You Talking About
- HDU 1075 What Are You Talking About
- hdu 1075 What Are You Talking About
- hdu 1075 What Are You Talking About(字典树)
- hdu-1075-What Are You Talking About
- HDU 1075 What Are You Talking About (字典树)
- HDU 1075 What Are You Talking About
- HDU 1075 What Are You Talking About(字典树)
- HDU- 1075 What Are You Talking About (Trie or map)
- HDU 1075 What Are You Talking About
- HDU-1075-What Are You Talking About
- HDU 1075 What Are You Talking About
- HDU_1075_What Are You Talking About(字典树)
- hdu 1075 What Are You Talking About (Trie树,水题)
- [字典树] HDU 1075 - What Are You Talking About
- hdu 1075 What Are You Talking About