题目链接https://pintia.cn/problem-sets/994805342720868352/problems/994805367156883456
题目大意:就是数制转换,注意各种edge cases就好
- 输入
0
,得到tret
- 输入
tret
,得到0
- 输入
tam
,得到13
完整代码
#include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <algorithm>
#include <queue>
#include <map>using namespace std;string str1[13] = {
"tret", "jan", "feb", "mar", "apr", "may", "jun", "jly", "aug", "sep", "oct", "nov", "dec"};
string str2[13] = {
"###", "tam", "hel", "maa", "huh", "tou", "kes", "hei", "elo", "syy", "lok", "mer", "jou"};void num2txt(int num) {
int high, low;high = num / 13;low = num % 13;if (high != 0) {
cout << str2[high];}if (high != 0 && low != 0)cout << " " << str1[low];else if (high == 0 && low != 0)cout << str1[low];else if (high == 0 && low == 0)cout << str1[low];cout << endl;
}int getNum1(string s) {
for (int i = 0; i < 13; i++) {
if (s == str1[i])return i;}return -1;
}int getNum2(string s) {
for (int i = 1; i < 13; i++) {
if (s == str2[i])return i;}return -1;
}void txt2num(string str) {
int ret = 0;if (str.size() == 4)ret = 0;else if (str.size() > 3) {
string high = str.substr(0, 3);string low = str.substr(4, 3);int num_high = getNum2(high);int num_low = getNum1(low);ret = num_low + num_high * 13;}else {
int num = getNum2(str);if (num != -1)ret = num * 13;elseret = getNum1(str);}cout << ret << endl;
}int main() {
int N;scanf("%d\n", &N);for (int i = 0; i < N; i++) {
string input;getline(cin, input);if (input[0] >= '0' && input[0] <= '9') {
num2txt(stoi(input));}else {
txt2num(input);}}return 0;
}