1100 Mars Numbers(二刷)

英文题目:1100 Mars Numbers

中文题目:1044 火星数字

 1 #include<iostream>
 2 #include<algorithm>
 3 using namespace std;
 4 string hashtable1[13] = {"tret","jan", "feb", "mar", "apr", "may", "jun", "jly", "aug", "sep", "oct", "nov", "dec"};
 5 string hashtable2[13] = {"","tam", "hel", "maa", "huh", "tou", "kes", "hei", "elo", "syy", "lok", "mer", "jou"};
 6 int main() {
 7     int n;
 8     cin>>n;
 9     getchar();
10     while(n--) {
11         string str1="",str2="";
12         getline(cin,str1);
13         if(isdigit(str1[0])) { //地球文
14             int t = stoi(str1);
15             if(t < 13)  cout<<hashtable1[t]<<endl;
16             else if(t % 13 == 0) cout<<hashtable2[t/13]<<endl;//如果是13的倍数,不输出末尾的 0
17             else cout<<hashtable2[t/13]<<" "<<hashtable1[t%13]<<endl;
18         } else { //外星文
19             int sum = 0;
20             if(str1.size() > 3) {
21                 str2 = str1.substr(0,3);//str2表示十位
22                 str1.erase(0,4);//str1表示个位
23             }
24             for(int i = 1; i <= 12; ++i) {//输出十位,或者13的倍数 
25                 if(hashtable2[i] == str2 || hashtable2[i] == str1)
26                     sum += i*13;
27             }
28             for(int i = 0; i <= 12; ++i) {//输出个位
29                 if(hashtable1[i] == str1)
30                     sum += i;
31             }
32             cout<<sum<<endl;
33         }
34     }
35     return 0;
36 }

 

posted @ 2020-03-27 13:05  tangq123  阅读(155)  评论(0编辑  收藏  举报