DEV Community

joinmoin0002
joinmoin0002

Posted on

USACO-T007: Name that Number

/*
ID: mickyta1
TASK: namenum
LANG: C++
*/

include

using namespace std;

const int N = 12;

char tmp[N + 1], enc[26];

string encode(string &str){
string ans = "";
for(int i = 0; i < str.size(); ++i){
ans += enc[str[i] - 'A'];
}
return ans;
}
.
int main(){

enc['A' - 'A'] = '2'; enc['B' - 'A'] = '2'; enc['C' - 'A'] = '2';
enc['D' - 'A'] = '3'; enc['E' - 'A'] = '3'; enc['F' - 'A'] = '3';
enc['G' - 'A'] = '4'; enc['H' - 'A'] = '4'; enc['I' - 'A'] = '4';
enc['J' - 'A'] = '5'; enc['K' - 'A'] = '5'; enc['L' - 'A'] = '5';
enc['M' - 'A'] = '6'; enc['N' - 'A'] = '6'; enc['O' - 'A'] = '6';
enc['P' - 'A'] = '7'; enc['R' - 'A'] = '7'; enc['S' - 'A'] = '7';
enc['T' - 'A'] = '8'; enc['U' - 'A'] = '8'; enc['V' - 'A'] = '8';
enc['W' - 'A'] = '9'; enc['X' - 'A'] = '9'; enc['Y' - 'A'] = '9';
enc['Q' - 'A'] = '.'; enc['Z' - 'A'] = '.';

freopen("namenum.in", "r", stdin);
Enter fullscreen mode Exit fullscreen mode

.
string tr;
cin >> tr;

fclose(stdin);
freopen("dict.txt", "r", stdin);
freopen("namenum.out", "w", stdout);

bool isFound = false;
while(scanf( "%s", tmp) != EOF){
    string str = tmp;
    if(encode(str) == tr){
        isFound = true;
        cout << str << '\n';
    }
}
if(!isFound){
    cout << "NONE\n";
}

fclose(stdin);
fclose(stdout);

return 0;
Enter fullscreen mode Exit fullscreen mode

}

.
.
.

Discussion (0)