1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
| #include <iostream> #include <algorithm> #include <stdio.h> #include <string> #include <sstream> #include <stack> #include <vector>
using namespace std;
string marnum[13] = {"tret", "jan", "feb", "mar", "apr", "may", "jun", "jly", "aug", "sep", "oct", "nov", "dec"}; string marshi[13] = {"", "tam", "hel", "maa", "huh", "tou", "kes", "hei", "elo", "syy", "lok", "mer", "jou"};
string tomar(string str) { stringstream ss; ss << str; int num; ss >> num; stack<int> st; while(num != 0) { st.push(num % 13); num = num / 13; } string result; if(st.size() == 0) { result = marnum[0]; } else if(st.size() == 1) { result += marnum[st.top()]; } else if(st.size() == 2) { result += marshi[st.top()]; st.pop(); if(st.top() != 0) result += " " + marnum[st.top()]; } return result; }
string toearth(string str) { if(find(marshi, marshi + 13, str) != marshi + 13) { return to_string((find(marshi, marshi + 13, str) - marshi) * 13); } int thespace = str.find(" "); if(thespace == -1) { return to_string(find(marnum, marnum + 13, str) - marnum); } else { string str1 = str.substr(0, thespace); int num1 = find(marshi, marshi + 13, str1) - marshi; string str2 = str.substr(thespace + 1, -1); int num2 = find(marnum, marnum + 13, str2) - marnum; return to_string(num1 * 13 + num2); } }
int main() { int n; cin >> n; getchar(); vector<string> result; for(int i = 1; i <= n; i++) { string str; getline(cin, str); if(isdigit(str[0])) { result.push_back(tomar(str)); } else { result.push_back(toearth(str)); } } for(auto it = result.begin(); it != result.end(); it++) { cout << *it << endl; } return 0; }
|