hdu 1075 What Are You Talking About2

http://acm.hdu.edu.cn/showproblem.php?pid=1075  map实现

View Code
 1 /*map实现,翻译*/
2 #include<iostream>
3 #include<cstring>
4 #include<cstdlib>
5 #include<map>
6 using namespace std;
7 map<string,string>mat;
8 void print(string s)//找出s对应的英语单词
9 {
10 if(mat[s].length()) printf("%s",mat[s].c_str());//found
11 else printf("%s",s.c_str());//not found
12 }
13 int main()
14 {
15 string a,b,line;
16 char c[20];
17 char ch[3008];
18 a.resize(12);
19 b.resize(12);
20 scanf("%s",c);//读取start
21 a="";
22 getchar();
23 while(scanf("%s",c)==1 && strcmp(c,"END")!=0)//
24 {
25 a=c;//string =char[]
26 scanf("%s",c);
27 b=c;
28 mat[b]=a;
29 }
30 scanf("%s",c);//读取start
31 getchar();//读回车
32 int i,len;
33 string temp;
34 while(gets(ch) && strcmp(ch,"END"))
35 {
36 //printf("line:%s\n",line);
37 line=ch;
38 temp="";
39 a="";
40 len=line.length();
41 for(i=0;i<len;i++)
42 {
43 if(isalpha(line[i])) temp+=line[i];
44 else
45 {
46 print(temp);//char*
47 temp="";
48 printf("%c",line[i]);
49 }
50 }
51 print(temp);
52 printf("\n");
53 }
54 system("pause");
55 return 0;
56 }


 

posted @ 2012-03-29 09:58  keepmoving89  阅读(145)  评论(0编辑  收藏  举报