-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy path1044.cpp
44 lines (40 loc) · 1.42 KB
/
1044.cpp
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
#include <cctype>
#include <iostream>
#include <sstream>
#include <string>
#include <map>
using namespace std;
const int BASE = 13;
string num2str(int num) {
static const string digits1[BASE] {"tret", "jan", "feb", "mar", "apr", "may", "jun", "jly", "aug", "sep", "oct", "nov", "dec"};
static const string digits2[BASE] {" ", "tam", "hel", "maa", "huh", "tou", "kes", "hei", "elo", "syy", "lok", "mer", "jou"};
string result;
if (num / BASE) {
result = digits2[num / BASE];
if (num % BASE) result += " " + digits1[num % BASE];
} else {
result = digits1[num % BASE];
}
return result;
}
int str2num(string str) {
static map<string, int> nums1 {{"jan", 1}, {"feb", 2}, {"mar", 3}, {"apr", 4}, {"may", 5}, {"jun", 6}, {"jly", 7}, {"aug", 8}, {"sep", 9}, {"oct", 10}, {"nov", 11}, {"dec", 12}, {"tret", 0}};
static map<string, int> nums2 {{"tam", 1}, {"hel", 2}, {"maa", 3}, {"huh", 4}, {"tou", 5}, {"kes", 6}, {"hei", 7}, {"elo", 8}, {"syy", 9}, {"lok", 10}, {"mer", 11}, {"jou", 12}};
int result = 0;
string num;
stringstream sin(str);
while (sin >> num)
result += nums2[num] * BASE + nums1[num];
return result;
}
int main() {
int n;
scanf("%d\n", &n);
while (n--) {
string s;
getline(cin, s);
if (isdigit(s[0])) cout << num2str(stoi(s)) << endl;
else cout << str2num(s) << endl;
}
return 0;
}