mickypinata

USACO-T007: Name that Number

Sep 20th, 2021
751
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2. ID: mickyta1
  3. TASK: namenum
  4. LANG: C++
  5. */
  6.  
  7. #include <bits/stdc++.h>
  8. using namespace std;
  9.  
  10. const int N = 12;
  11.  
  12. char tmp[N + 1], enc[26];
  13.  
  14. string encode(string &str){
  15.     string ans = "";
  16.     for(int i = 0; i < str.size(); ++i){
  17.         ans += enc[str[i] - 'A'];
  18.     }
  19.     return ans;
  20. }
  21.  
  22. int main(){
  23.  
  24.     enc['A' - 'A'] = '2'; enc['B' - 'A'] = '2'; enc['C' - 'A'] = '2';
  25.     enc['D' - 'A'] = '3'; enc['E' - 'A'] = '3'; enc['F' - 'A'] = '3';
  26.     enc['G' - 'A'] = '4'; enc['H' - 'A'] = '4'; enc['I' - 'A'] = '4';
  27.     enc['J' - 'A'] = '5'; enc['K' - 'A'] = '5'; enc['L' - 'A'] = '5';
  28.     enc['M' - 'A'] = '6'; enc['N' - 'A'] = '6'; enc['O' - 'A'] = '6';
  29.     enc['P' - 'A'] = '7'; enc['R' - 'A'] = '7'; enc['S' - 'A'] = '7';
  30.     enc['T' - 'A'] = '8'; enc['U' - 'A'] = '8'; enc['V' - 'A'] = '8';
  31.     enc['W' - 'A'] = '9'; enc['X' - 'A'] = '9'; enc['Y' - 'A'] = '9';
  32.     enc['Q' - 'A'] = '.'; enc['Z' - 'A'] = '.';
  33.  
  34.     freopen("namenum.in", "r", stdin);
  35.  
  36.     string tr;
  37.     cin >> tr;
  38.  
  39.     fclose(stdin);
  40.     freopen("dict.txt", "r", stdin);
  41.     freopen("namenum.out", "w", stdout);
  42.  
  43.     bool isFound = false;
  44.     while(scanf( "%s", tmp) != EOF){
  45.         string str = tmp;
  46.         if(encode(str) == tr){
  47.             isFound = true;
  48.             cout << str << '\n';
  49.         }
  50.     }
  51.     if(!isFound){
  52.         cout << "NONE\n";
  53.     }
  54.  
  55.     fclose(stdin);
  56.     fclose(stdout);
  57.  
  58.     return 0;
  59. }
  60.  
RAW Paste Data