13
//题目的意思就是首先输入一个n,表示要翻译的数字测试组数//然后对于每一个测试组://可能是 Earth number or Mars number/*对于 Earth numer :也就是输入是数字的情况,我进行了以下判断:如果 <13 和 >= 13 ,但是其中有一个坑就是,对于整数例如13 26 ,只需要输出对应的s2. */ /*对于 Mars number :用了两个check来返回相应的下标,因为提交了了好几次,改了好几次第一种的那情况,没认真看仔细这个。就是:因为我用的是输入字符串的长度来分情况,因为我们可以从题目中看出的是,"jan","feb",..这些都是3个长度的字符串,除了第一个0的情况,所以我首先排除0,然后 进行不同的,就ok了 *//*题目还用到了了streamstring 类型,因为我用getline(cin ,s)输入的string 类型字符串,如果是数字的情况,我想把string 转换成 int 类型的t,stremstring stream;stream << s;//把string类型的s 扔到 流 streamstring >> t; //再通过 stream,把值赋给int 类型的t */#include <iostream>#include <sstream>#include <string>using namespace std;// s1 -> 1-12// s2 -> 13-24 const string s1[13] = {"tret","jan", "feb", "mar", "apr", "may", "jun", "jly", "aug", "sep", "oct", "nov", "dec"}; const string s2[12] = {"tam", "hel", "maa", "huh", "tou", "kes", "hei", "elo", "syy", "lok", "mer", "jou"};int check1(string s) { for ( int i = 0; i < 13; i++ ) { if ( s1[i] == s ) return i; } return 0;}int check2(string s) { for ( int i = 0; i < 12; i++ ) { if ( s2[i] == s ) { return i+1; } } return 0;}int main() { int n; cin >> n; string s; stringstream stream; getchar(); while ( n-- ) { getline(cin, s); if (isdigit(s[0])) { int t = 0; stream << s; stream >> t; if ( t >= 0 ) { if ( t < 13 ) { cout << s1[t] << endl; stream.clear(); } else {// >= 13 int t1 = t%13; int t2 = t/13; if ( t1 == 0 ) cout << s2[t2-1] << endl; else { cout << s2[t2-1] << " " << s1[t1] << endl; } stream.clear(); } } } else { int len = s.length(); if ( s == "tret") cout << 0 << endl; else if ( len == 3 ) { if (check1(s)) cout << check1(s) << endl; if (check2(s)) cout << (13)*check2(s) << endl; } else { string s1,s2; for ( int j = 0; s[j] != ' '; j++ ) { s1.push_back(s[j]); } for ( int j = 4; j < len; j++ ) { s2.push_back(s[j]); } int k1 = check2(s1); int k2 = check1(s2); cout << k1*13+k2 << endl; } } } return 0;}
新闻热点
疑难解答