标签:des style class blog code http
Babelfish
Time Limit: 3000MS | Memory Limit: 65536K | |
Total Submissions: 30816 | Accepted: 13283 |
Description
Input
Output
Sample Input
dog ogday cat atcay pig igpay froot ootfray loops oopslay atcay ittenkay oopslay
Sample Output
cat eh loops
Hint
Source
1 #include <iostream>
2 #include <string.h>
3 #include <stdio.h>
4
5 using namespace std;
6 struct Tire{
7 Tire *next[26];
8 char *trans;
9 Tire()
10 {
11 int i;
12 for(i=0;i<26;i++)
13 next[i] = NULL;
14 trans = NULL;
15 }
16 } root;
17
18 void Insert(char word[],char trans[])
19 {
20 Tire *p = &root;
21 int i;
22 for(i=0;word[i];i++){
23 int t = word[i] - ‘a‘;
24 if(p->next[t]==NULL)
25 p->next[t] = new Tire;
26 p = p->next[t];
27 }
28 p->trans = new char[11];
29 strcpy(p->trans,trans);
30 }
31
32 void Find(char word[]) //查找该单词的翻译并输出,如果没有则输出eh
33 {
34 Tire *p = &root;
35 int i;
36 for(i=0;word[i];i++){
37 int t = word[i] - ‘a‘;
38 if(p->next[t]==NULL){
39 printf("eh\n");
40 return ;
41 }
42 p = p->next[t];
43 }
44 if(p->trans!=NULL)
45 printf("%s\n",p->trans);
46 else //没找到
47 printf("eh");
48 }
49
50 int main()
51 {
52 char str[11];
53 while(gets(str)){
54 if(str[0]==‘\0‘) //检测到空行
55 break;
56 char trans[11],word[11];
57 sscanf(str,"%s%s",trans,word);
58 Insert(word,trans);
59 }
60 while(scanf("%s",str)!=EOF) //读取要翻译的单词
61 Find(str);
62 return 0;
63 }
Freecode : www.cnblogs.com/yym2013
poj 2503:Babelfish(字典树,经典题,字典翻译),布布扣,bubuko.com
poj 2503:Babelfish(字典树,经典题,字典翻译)
标签:des style class blog code http
原文地址:http://www.cnblogs.com/yym2013/p/3789136.html