-
Notifications
You must be signed in to change notification settings - Fork 0
/
namenum.cpp
99 lines (89 loc) · 2.21 KB
/
namenum.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
/*
ID: bbsunch2
PROG: namenum
LANG: C++
*/
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <stdlib.h>
using namespace std;
char number_letter[10][3] = {
{},// 0
{},// 1
{'A','B','C'}, // 2
{'D','E','F'}, // 3
{'G','H','I'}, // 4
{'J','K','L'}, // 5
{'M','N','O'}, // 6
{'P','R','S'}, // 7
{'T','U','V'}, // 8
{'W','X','Y'} // 9
};
int main()
{
ofstream fout ("namenum.out");
ifstream fin ("namenum.in");
ifstream fdict ("dict.txt");
string word;
vector <string> dicts;
while(fdict.good() && !fdict.eof())
{
getline(fdict,word,'\n');
dicts.push_back(word);
}
string num;
fin >> num;
int numSize = num.size();
for(vector<string>::iterator iter=dicts.begin();iter!=dicts.end();)
{
word = *iter;
int wordSize = word.size();
if(wordSize != numSize)
{
dicts.erase(iter);
continue;
}
++iter;
}
for(int i = 0; i < numSize; i++)
{
int rightNum = (int)num[i] - 48;
for(vector<string>::iterator iter=dicts.begin();iter!=dicts.end();)
{
word = *iter;
char rightLetter = word[i];
bool key = false;
for(int j = 0; j < 3; j++)
{
char letter = number_letter[rightNum][j];
if(letter == rightLetter)
{
key = true;
break;
}
}
if(key)
{
++iter;
}else
{
dicts.erase(iter);
continue;
}
}
}
if(dicts.size() == 0)
{
fout << "NONE" << endl;
}else
{
for(vector<string>::iterator iter=dicts.begin();iter!=dicts.end();++iter)
{
word = *iter;
fout << word << endl;
}
}
return 0;
}