百练 2804 词典 解题呈报   
               添加时间:2013-6-11 点击量: 
 
              1.Link:http://poj.grids.cn/practice/2804/
2.content
- 总时候限制:
 - 3000ms
 - 内存限制:
 - 65536kB
 
- 描述
 - 你旅游到了一个国外的城市。那边的人们说的外国说话你不克不及懂得。不过荣幸的是,你有一本词典可以帮助你。
 - 输入
 - 起首输入一个词典,词典中包含不跨越100000个词条,每个词条占领一行。每一个词条包含一个英文单词和一个外语单词,两个单词之间用一个 空格隔开。并且在词典中不会有某个外语单词呈现跨越两次。词典之后是一个空行,然后给出一个由外语单词构成的文档,文档不跨越100000行,并且每行只 包含一个外语单词。输入中呈现单词只包含小写字母,并且长度不会跨越10。
 - 输出
 - 在输出中,你须要把输入文档翻译成英文,每行输出一个英文单词。若是某个外语单词不在词典中,就把这个单词翻译成“eh”。
 - 样例输入
 - 
dog ogday
cat atcay
pig igpay
froot ootfray
loops oopslay
atcay
ittenkay
oopslay
 - 样例输出
 - 
cat
eh
loops
 - 提示
 - 输入斗劲大,推荐应用C说话的I / O函数。
 
3.code
 1 #include <stdio.h>
 2 #include <string.h>
 3 #include <algorithm>
 4 
 5 
 6 #define MAXSTR 11
 7 #define MAXWORD 100010
 8 
 9 using namespace std;
10 
11 typedef struct
12 {
13     char foreign[MAXSTR];
14     char english[MAXSTR];
15 }  m_word;
16 
17 m_word m_dic[MAXWORD];
18 
19 int compare(const void elem1,const void elem2)
20 {
21     return strcmp(((m_word)elem1)->foreign,((m_word)elem2)->foreign);
22 }
23 
24 int main()
25 {
26     int count = 0;
27     
28     char chs[30];
29     
30     while(fgets(chs,29,stdin),chs[0] != \n)
31     {
32         sscanf(chs,%s%s,m_dic[count].english,m_dic[count].foreign);
33         count++;
34     }
35     
36     qsort(m_dic,count,sizeof(m_word),compare);
37     
38     
39     m_word tmp;
40     m_word ans;
41     while(scanf(%s,tmp.foreign) != EOF)
42     {
43         ans = (m_word)bsearch(&tmp,m_dic,count,sizeof(m_word),compare);
44         
45         if(ans != NULL) printf(%s\n,ans->english);
46         else printf(eh\n);
47     }
48 
49     
50     return 0;
51 }
4.method
(1)fgets+sscanf
(2)qsort+bsearch
                     
                  
     
  
 
    
    
1.Link:http://poj.grids.cn/practice/2804/
2.content
- 总时候限制:
 - 3000ms
 - 内存限制:
 - 65536kB
 
- 描述
 - 你旅游到了一个国外的城市。那边的人们说的外国说话你不克不及懂得。不过荣幸的是,你有一本词典可以帮助你。
 - 输入
 - 起首输入一个词典,词典中包含不跨越100000个词条,每个词条占领一行。每一个词条包含一个英文单词和一个外语单词,两个单词之间用一个 空格隔开。并且在词典中不会有某个外语单词呈现跨越两次。词典之后是一个空行,然后给出一个由外语单词构成的文档,文档不跨越100000行,并且每行只 包含一个外语单词。输入中呈现单词只包含小写字母,并且长度不会跨越10。
 - 输出
 - 在输出中,你须要把输入文档翻译成英文,每行输出一个英文单词。若是某个外语单词不在词典中,就把这个单词翻译成“eh”。
 - 样例输入
  dog ogday
cat atcay
pig igpay
froot ootfray
loops oopslay
atcay
ittenkay
oopslay- 样例输出
  cat
eh
loops- 提示
 - 输入斗劲大,推荐应用C说话的I / O函数。
 
3.code
1 #include <stdio.h>
2 #include <string.h>
3 #include <algorithm>
4
5
6 #define MAXSTR 11
7 #define MAXWORD 100010
8
9 using namespace std;
10
11 typedef struct
12 {
13 char foreign[MAXSTR];
14 char english[MAXSTR];
15 } m_word;
16
17 m_word m_dic[MAXWORD];
18
19 int compare(const void elem1,const void elem2)
20 {
21 return strcmp(((m_word)elem1)->foreign,((m_word)elem2)->foreign);
22 }
23
24 int main()
25 {
26 int count = 0;
27
28 char chs[30];
29
30 while(fgets(chs,29,stdin),chs[0] != \n)
31 {
32 sscanf(chs,%s%s,m_dic[count].english,m_dic[count].foreign);
33 count++;
34 }
35
36 qsort(m_dic,count,sizeof(m_word),compare);
37
38
39 m_word tmp;
40 m_word ans;
41 while(scanf(%s,tmp.foreign) != EOF)
42 {
43 ans = (m_word)bsearch(&tmp,m_dic,count,sizeof(m_word),compare);
44
45 if(ans != NULL) printf(%s\n,ans->english);
46 else printf(eh\n);
47 }
48
49
50 return 0;
51 }
4.method
(1)fgets+sscanf
(2)qsort+bsearch




