Posted on 2009-03-15 10:23
superman 阅读(115)
评论(0) 编辑 收藏 引用 所属分类:
USACO
1 #include <fstream>
2
3 using namespace std;
4
5 int letter2num(const char c)
6 {
7 switch (c)
8 {
9 case 'A' : case 'B' : case 'C' : return 2;
10 case 'D' : case 'E' : case 'F' : return 3;
11 case 'G' : case 'H' : case 'I' : return 4;
12 case 'J' : case 'K' : case 'L' : return 5;
13 case 'M' : case 'N' : case 'O' : return 6;
14 case 'P' : case 'R' : case 'S' : return 7;
15 case 'T' : case 'U' : case 'V' : return 8;
16 case 'W' : case 'X' : case 'Y' : return 9;
17 }
18 }
19
20 int main()
21 {
22 ifstream fin("namenum.in");
23 ifstream fin_dict("dict.txt");
24 ofstream fout("namenum.out");
25
26 string num, name;
27 int cnt = 0;
28
29 fin >> num;
30 while (fin_dict >> name)
31 {
32 if (num.size() != name.size())
33 continue;
34
35 unsigned i;
36 for (i = 0; i < name.size(); i++)
37 if (letter2num(name[i]) != num[i] - '0')
38 break;
39 if (i == name.size())
40 {
41 cnt++;
42 fout << name << endl;
43 }
44 }
45
46 if (cnt == 0)
47 fout << "NONE" << endl;
48
49 return 0;
50 }
51