题目:https://pintia.cn/problem-sets/994805260223102976/problems/994805279328157696
坑点
这题调试半天没过,最后发现是因为num初始化在循环外面。。。真是醉了。
代码
#include <iostream>#include <map>#include <string>#include <cstring>using namespace std;string list1[13] = {"tret", "jan", "feb", "mar", "apr", "may", "jun", "jly", "aug", "sep", "oct", "nov", "dec"};string list2[13] = {"error","tam", "hel", "maa", "huh", "tou", "kes", "hei", "elo", "syy", "lok", "mer", "jou"};map<string, int> str_to_num;string num_to_str[170];void init(){//初始化num_to_strfor(int i = 0; i < 13; i++){num_to_str[i] = list1[i];}for(int i = 13; i < 169; i++){if(i % 13 == 0)num_to_str[i] = list2[i/13];else num_to_str[i] = list2[i/13] + " " + list1[i%13];}//初始化str_to_numfor(int i = 0; i < 169; i++){str_to_num[num_to_str[i]] = i;}}int main() {init();int n;string tempstr;scanf("%d",&n);getchar();for(int i = 0; i < n; i++){int num = 0;getline(cin, tempstr);if(tempstr[0]<='9' && tempstr[0] >= '0'){for(int j = 0; j < tempstr.size(); j++){num = num * 10 + tempstr[j] - '0';}cout<<num_to_str[num]<<endl;} else {cout<<str_to_num[tempstr]<<endl;}}return 0;}
