/**************************
//@Author: 3stone
//@ACM: PAT-A1100
//@Time: 18/1/25
//@IDE: VS2017
***************************/
#include<cstdio>
#include<iostream>
#include<map>
#include<algorithm>
#include<string>
#include<cstring>
using namespace std;
/*
//题目没有明说,对于Mars,当高位有值,低位为0时,只输出高位
//如 26 应该表示为 hel 而不是 hel tret
*/
void earthToMars(string tar, string str1[], string str2[]) {
char data[20];
strcpy(data, tar.c_str());
int value;
sscanf(data, "%d", &value); //转为int值
int single = value % 13;
int tens = value / 13;
if (tens != 0 && single != 0) cout << str2[tens] << " " << str1[single] << endl;
else if (single != 0) cout << str1[single] << endl;
else if (tens != 0) cout << str2[tens] << endl;
else cout << str1[single] << endl;
}
void marsToEarth(string str, map<string, int> m1, map<string, int> m2) {
if (str.find(" ") == string::npos) {//只有一位 (有可能是高位)
if (m1.find(str) != m1.end())
cout << m1[str] << endl;
else
cout << m2[str] * 13 << endl;
}
else {
int key = str.find(" "); // 查找空格
string s1, s2;
s1 = str.substr(0, key);
s2 = str.substr(key + 1, str.size() - key - 1);
int value = m1[s2] + m2[s1] * 13;
cout << value << endl;
}
}
int main() {
map<string, int> m1, m2;
string str1[14] = {"tret", "jan", "feb", "mar", "apr", "may", "jun", "jly", "aug", "sep", "oct", "nov", "dec", "tam"};
string str2[13] = {"", "tam", "hel", "maa", "huh", "tou", "kes", "hei", "elo", "syy", "lok", "mer", "jou"};
for (int i = 0; i < 13; i++)
m1[str1[i]] = i;
for (int i = 1; i < 13; i++)
m2[str2[i]] = i;
int n;
cin >> n;
getchar();//吸收换行符
for (int j = 0; j < n; j++) {
char tempChars[20]; // 空格string读取不进来啊
gets(tempChars);
string tempStr = tempChars;
if ('0' <= tempStr[0] && tempStr[0] <= '9')
earthToMars(tempStr, str1, str2);
else {
marsToEarth(tempStr, m1, m2);
}
}
return 0;
}
PAT-A1100 & PAT-B1044
猜你喜欢
转载自blog.csdn.net/qq_26398495/article/details/79159381
今日推荐
周排行