分值 : 20 难度 : 中等题 思路 : string 读入然后 转化 坑点 : string 转 int / int转string有点生疏
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
#include <iostream>using namespace std;string A[13] = {"","jan", "feb", "mar", "apr", "may", "jun", "jly", "aug", "sep", "oct", "nov", "dec"};string B[13] = {"","tam", "hel", "maa", "huh", "tou", "kes", "hei", "elo", "syy", "lok", "mer", "jou"};int find1(string s){ for(int i =1 ; i< 13 ; i++) { if(A[i] == s) return i ; } return 0 ;}int find2(string s){ for(int i =1 ; i< 13 ; i++) { if(B[i] == s) return i ; } return 0;}int main() { int N ; cin >> N ; getchar() ; for(int i = 0 ; i< N ; i++) { string temp ; getline(cin , temp) ; if(isdigit(temp[0])) { int num = atoi(temp.c_str()) ; int l = num %13 ; int h = num /13 ; if(l== 0 && h == 0 ) cout <<"tret" <<endl ; else if (l==0) cout << B[h] <<endl ; else if( h==0) cout << A[l] <<endl ; else cout << B[h] <<" "<<A[l] <<endl ; } else { int end = 0 ; while (temp[end]!=' ' && end < temp.size()) end ++ ; int h = 0 , l = 0 ; if(end == temp.size()) // 只有一个 { if(find1(temp)) l = find1(temp) ; else h = find2(temp) ; } else{ string t1 = temp.substr(0,end ); string t2 = temp.substr(end+1 ); h = find2(t1) ; l = find1(t2) ; } cout << h*13+l <<endl ; } }}