zoukankan      html  css  js  c++  java
  • B1044/A1100:Mars Numbers (20)

     题意:字符串数字13进制转换

     AC代码

     方法一:循环方式存入 13 * 13 个数后输出

     1 #include<bits/stdc++.h>
     2 using namespace std;
     3 string unit[] = {"tret", "jan", "feb", "mar", "apr", "may", "jun", "jly", "aug", "sep", "oct", "nov", "dec"};
     4 string tens[] = {"tret", "tam", "hel", "maa", "huh", "tou", "kes", "hei", "elo", "syy", "lok", "mer", "jou"};
     5 string numToStr[170];
     6 unordered_map<string, int> strToNum;
     7 int main()
     8 {
     9     for(int i = 0; i < 13; i++) {
    10         numToStr[i] = unit[i]; strToNum[unit[i]] = i;
    11         numToStr[i*13] = tens[i]; strToNum[tens[i]] = i * 13;
    12     }
    13     for(int i = 1; i < 13; i++){
    14         for(int j = 1; j < 13; j++)
    15         {
    16             string s = tens[i] + ' ' + unit[j];
    17             numToStr[i * 13 + j] = s;
    18             strToNum[s] = i * 13 + j;
    19         }
    20     }  
    21     int N; string str;
    22     cin >> N;
    23     getchar();
    24     for(int i = 0; i < N; i++) {
    25         getline(cin, str);
    26         if(str[0] >= '0' && str[0] <= '9') { int num = stoi(str); cout << numToStr[num] << endl;} 
    27         else cout << strToNum[str] << endl;
    28     } return 0;
    29 }

     方法二:搬砖存储法(适用于不动脑 喜搬砖者)亲测 50 min 搬完后胸闷心悸肚子饿

     1 #include<bits/stdc++.h>
     2 using namespace std;
     3 unordered_map<string, int> strToNum = { 
     4     {"tret",0}, {"jan",1}, {"feb",2}, {"mar",3}, {"apr",4}, {"may",5}, {"jun",6}, {"jly",7}, {"aug",8}, {"sep",9}, {"oct",10}, {"nov",11}, {"dec",12}
     5     , {"tam",13}, {"tam jan",14}, {"tam feb",15}, {"tam mar",16}, {"tam apr",17}, {"tam may",18}, {"tam jun",19}, {"tam jly",20}, {"tam aug",21}, {"tam sep",22}, {"tam oct",23}, {"tam nov",24}, {"tam dec",25}
     6     , {"hel",26}, {"hel jan",27}, {"hel feb",28}, {"hel mar",29}, {"hel apr",30}, {"hel may",31}, {"hel jun",32}, {"hel jly",33}, {"hel aug",34}, {"hel sep",35}, {"hel oct",36}, {"hel nov",37}, {"hel dec",38}
     7     , {"maa",39}, {"maa jan",40}, {"maa feb",41}, {"maa mar",42}, {"maa apr",43}, {"maa may",44}, {"maa jun",45}, {"maa jly",46}, {"maa aug",47}, {"maa sep",48}, {"maa oct",49}, {"maa nov",50}, {"maa dec",51}
     8     , {"huh",52}, {"huh jan",53}, {"huh feb",54}, {"huh mar",55}, {"huh apr",56}, {"huh may",57}, {"huh jun",58}, {"huh jly",59}, {"huh aug",60}, {"huh sep",61}, {"huh oct",62}, {"huh nov",63}, {"huh dec",64}
     9     , {"tou",65}, {"tou jan",66}, {"tou feb",67}, {"tou mar",68}, {"tou apr",69}, {"tou may",70}, {"tou jun",71}, {"tou jly",72}, {"tou aug",73}, {"tou sep",74}, {"tou oct",75}, {"tou nov",76}, {"tou dec",77}
    10     , {"kes",78}, {"kes jan",79}, {"kes feb",80}, {"kes mar",81}, {"kes apr",82}, {"kes may",83}, {"kes jun",84}, {"kes jly",85}, {"kes aug",86}, {"kes sep",87}, {"kes oct",88}, {"kes nov",89}, {"kes dec",90}
    11     , {"hei",91}, {"hei jan",92}, {"hei feb",93}, {"hei mar",94}, {"hei apr",95}, {"hei may",96}, {"hei jun",97}, {"hei jly",98}, {"hei aug",99}, {"hei sep",100}, {"hei oct",101}, {"hei nov",102}, {"hei dec",103}
    12     , {"elo",104}, {"elo jan",105}, {"elo feb",106}, {"elo mar",107}, {"elo apr",108}, {"elo may",109}, {"elo jun",110}, {"elo jly",111}, {"elo aug",112}, {"elo sep",113}, {"elo oct",114}, {"elo nov",115}, {"elo dec",116}
    13     , {"syy",117}, {"syy jan",118}, {"syy feb",119}, {"syy mar",120}, {"syy apr",121}, {"syy may",122}, {"syy jun",123}, {"syy jly",124}, {"syy aug",125}, {"syy sep",126}, {"syy oct",127}, {"syy nov",128}, {"syy dec",129}
    14     , {"lok",130}, {"lok jan",131}, {"lok feb",132}, {"lok mar",133}, {"lok apr",134}, {"lok may",135}, {"lok jun",136}, {"lok jly",137}, {"lok aug",138}, {"lok sep",139}, {"lok oct",140}, {"lok nov",141}, {"lok dec",142}
    15     , {"mer",143}, {"mer jan",144}, {"mer feb",145}, {"mer mar",146}, {"mer apr",147}, {"mer may",148}, {"mer jun",149}, {"mer jly",150}, {"mer aug",151}, {"mer sep",152}, {"mer oct",153}, {"mer nov",154}, {"mer dec",155}
    16     , {"jou",156}, {"jou jan",157}, {"jou feb",158}, {"jou mar",159}, {"jou apr",160}, {"jou may",161}, {"jou jun",162}, {"jou jly",163}, {"jou aug",164}, {"jou sep",165}, {"jou oct",166}, {"jou nov",167}, {"jou dec",168}, {"tam tam",169} };
    17 string numToStr[170] = {
    18     "tret", "jan", "feb", "mar", "apr", "may", "jun", "jly", "aug", "sep", "oct", "nov", "dec"
    19     , "tam", "tam jan", "tam feb", "tam mar", "tam apr", "tam may", "tam jun", "tam jly", "tam aug", "tam sep", "tam oct", "tam nov", "tam dec"
    20     , "hel", "hel jan", "hel feb", "hel mar", "hel apr", "hel may", "hel jun", "hel jly", "hel aug", "hel sep", "hel oct", "hel nov", "hel dec"
    21     , "maa", "maa jan", "maa feb", "maa mar", "maa apr", "maa may", "maa jun", "maa jly", "maa aug", "maa sep", "maa oct", "maa nov", "maa dec"
    22     , "huh", "huh jan", "huh feb", "huh mar", "huh apr", "huh may", "huh jun", "huh jly", "huh aug", "huh sep", "huh oct", "huh nov", "huh dec"
    23     , "tou", "tou jan", "tou feb", "tou mar", "tou apr", "tou may", "tou jun", "tou jly", "tou aug", "tou sep", "tou oct", "tou nov", "tou dec"
    24     , "kes", "kes jan", "kes feb", "kes mar", "kes apr", "kes may", "kes jun", "kes jly", "kes aug", "kes sep", "kes oct", "kes nov", "kes dec"
    25     , "hei", "hei jan", "hei feb", "hei mar", "hei apr", "hei may", "hei jun", "hei jly", "hei aug", "hei sep", "hei oct", "hei nov", "hei dec"
    26     , "elo", "elo jan", "elo feb", "elo mar", "elo apr", "elo may", "elo jun", "elo jly", "elo aug", "elo sep", "elo oct", "elo nov", "elo dec"
    27     , "syy", "syy jan", "syy feb", "syy mar", "syy apr", "syy may", "syy jun", "syy jly", "syy aug", "syy sep", "syy oct", "syy nov", "syy dec"
    28     , "lok", "lok jan", "lok feb", "lok mar", "lok apr", "lok may", "lok jun", "lok jly", "lok aug", "lok sep", "lok oct", "lok nov", "lok dec"
    29     , "mer", "mer jan", "mer feb", "mer mar", "mer apr", "mer may", "mer jun", "mer jly", "mer aug", "mer sep", "mer oct", "mer nov", "mer dec"
    30     , "jou", "jou jan", "jou feb", "jou mar", "jou apr", "jou may", "jou jun", "jou jly", "jou aug", "jou sep", "jou oct", "jou nov", "jou dec", "tam tam" };
    31 int main()
    32 {
    33     int N; string str;
    34     cin >> N;
    35     getchar();
    36     for(int i = 0; i < N; i++) {
    37         getline(cin, str);
    38         if(str[0] >= '0' && str[0] <= '9') {
    39             int num = stoi(str); cout << numToStr[num] << endl;
    40         } else {
    41             cout << strToNum[str] << endl;
    42         }
    43     } return 0;
    44 }

    搬完后胸闷心悸肚子饿

  • 相关阅读:
    __PRETTY_FUNCTION__, __FUNCTION__, __func__
    Python.with
    golang配置
    论单位转个人的社保金融社保卡的作用
    面试题
    平衡是一门艺术
    画原型是节省人力的最好办法
    推荐给非互联网主体的用户
    iOS 点击返回键崩溃的未解之谜
    服务请求比较慢SYN flooding
  • 原文地址:https://www.cnblogs.com/kamisamalz/p/13234569.html
Copyright © 2011-2022 走看看