这又是一道hash题。。。
注意点:
地球文如果是13的倍数,那么转换成火星文只输出一个单词,比如 13 要输出 tam;
同样,如果火星文是13的倍数,也只会给出一个单词,比如tam,转换成地球文后输出是13。
#include<iostream> #include<algorithm> using namespace std; string hashtable1[13] = {"tret","jan", "feb", "mar", "apr", "may", "jun", "jly", "aug", "sep", "oct", "nov", "dec"}; string hashtable2[13] = {"","tam", "hel", "maa", "huh", "tou", "kes", "hei", "elo", "syy", "lok", "mer", "jou"}; int main() { int n; cin>>n; getchar(); while(n--) { string str1="",str2=""; getline(cin,str1); if(isdigit(str1[0])) { //地球文 int t = stoi(str1); if(t < 13) cout<<hashtable1[t]<<endl; else if(t % 13 == 0) cout<<hashtable2[t/13]<<endl;//如果是13的倍数,不输出末尾的 0 else cout<<hashtable2[t/13]<<" "<<hashtable1[t%13]<<endl; } else { //外星文 int sum = 0; if(str1.size() > 3) { str2 = str1.substr(0,3);//str2表示十位 str1.erase(0,4);//str1表示个位 } for(int i = 1; i <= 12; ++i) {//输出十位,或者13的倍数 if(hashtable2[i] == str2 || hashtable2[i] == str1) sum += i*13; } for(int i = 0; i <= 12; ++i) {//输出个位 if(hashtable1[i] == str1) sum += i; } cout<<sum<<endl; } } return 0; }
原文:https://www.cnblogs.com/keep23456/p/12333015.html