사전을 구축해 두고, 일치하는 string을 찾는 문제.
int main() {
ofstream fout ("namenum.out");
ifstream fin ("namenum.in");
ifstream fin_dict("dict.txt");
vector<string> dict;
string s;
while(fin_dict >> s) dict.pb(s);
fin >> s;
char key[8][3] ={{'A','B','C'},{'D','E','F'}, {'G','H','I'}, {'J','K','L'}, {'M','N','O'}, {'P','R','S'},{'T','U','V'},{'W','X','Y'}};
int cnt = 0;
REP(i, dict.size())
{
string d = dict[i];
if( d.size() != s.size()) continue;
if( s.find('0') != string::npos || s.find('1') != string::npos ) break;
REP(j, d.size())
{
if( d[j] != key[s[j]-'0'-2][0] && d[j] != key[s[j]-'0'-2][1] && d[j] != key[s[j]-'0'-2][2]) break;
if( j == d.size()-1 )
{
fout << d << endl;
cnt++;
}
}
}
if( cnt == 0) fout << "NONE" << endl;
return 0;
}
----------------------------------------------------------------------------------------------------
int main() {
ofstream fout ("namenum.out");
ifstream fin ("namenum.in");
ifstream fin_dict("dict.txt");
vector<string> dict;
string s;
while(fin_dict >> s) dict.pb(s);
fin >> s;
char key[8][3] ={{'A','B','C'},{'D','E','F'}, {'G','H','I'}, {'J','K','L'}, {'M','N','O'}, {'P','R','S'},{'T','U','V'},{'W','X','Y'}};
int cnt = 0;
REP(i, dict.size())
{
string d = dict[i];
if( d.size() != s.size()) continue;
if( s.find('0') != string::npos || s.find('1') != string::npos ) break;
REP(j, d.size())
{
if( d[j] != key[s[j]-'0'-2][0] && d[j] != key[s[j]-'0'-2][1] && d[j] != key[s[j]-'0'-2][2]) break;
if( j == d.size()-1 )
{
fout << d << endl;
cnt++;
}
}
}
if( cnt == 0) fout << "NONE" << endl;
return 0;
}
----------------------------------------------------------------------------------------------------
TASK: namenum
LANG: C++
Compiling...
Compile: OK
Executing...
Test 1: TEST OK [0.011 secs, 2848 KB]
Test 2: TEST OK [0.022 secs, 2848 KB]
Test 3: TEST OK [0.000 secs, 2848 KB]
Test 4: TEST OK [0.000 secs, 2844 KB]
Test 5: TEST OK [0.011 secs, 2844 KB]
Test 6: TEST OK [0.011 secs, 2844 KB]
Test 7: TEST OK [0.011 secs, 2844 KB]
Test 8: TEST OK [0.011 secs, 2848 KB]
Test 9: TEST OK [0.011 secs, 2844 KB]
Test 10: TEST OK [0.011 secs, 2848 KB]
Test 11: TEST OK [0.022 secs, 2848 KB]
Test 12: TEST OK [0.022 secs, 2844 KB]
Test 13: TEST OK [0.011 secs, 2848 KB]
Test 14: TEST OK [0.011 secs, 2848 KB]
Test 15: TEST OK [0.000 secs, 2848 KB]
All tests OK.
YOUR PROGRAM ('namenum') WORKED FIRST TIME! That's fantastic
-- and a rare thing. Please accept these special automated
congratulation
반응형