PAT乙级1044
Posted zju-loser
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了PAT乙级1044相关的知识,希望对你有一定的参考价值。
自己写的AC代码,不是很难。之前写甲级的时候有这个题,当时没有继续做下去,看到了一下思路,就是枚举,把0-169的火星数字都和地球数字对应起来,过了一个月写乙级这题的时候我就沿用了这个思路,用map映射来写,写出来了,以后写题一定要记得多看题目的参数范围,小的话直接枚举暴力就行。这也是一道进制题。
#include<cstdio> #include<iostream> #include<string> #include<cctype> #include<algorithm> #include<map> using namespace std; int n; string gw[13] = { "tret","jan","feb","mar","apr","may","jun","jly","aug","sep","oct","nov","dec" }; string sw[12] = { "tam", "hel", "maa", "huh", "tou", "kes", "hei", "elo", "syy", "lok", "mer", "jou" }; map<int, string>vi; int a, b; void change(int tmp) { int x, y; int result = 0; for (x = 0; x < 13; x++) { for (y = 0; y < 13; y++) { if (x * 13 + y == tmp) { a = x; b = y; return; } } } } void initial() { for (int i = 0; i < 169; i++) { change(i); if (a == 0) { vi[i] = gw[b]; } else { if (b == 0) { vi[i] = sw[a - 1]; } else vi[i] = sw[a - 1] + " " + gw[b]; } } } int main() { initial(); cin >> n; getchar(); for (int i = 0; i < n; i++) { string str; getline(cin, str); if (isdigit(str[0])) { cout << vi[stoi(str)] << endl; } else { for (int i = 0; i < 169; i++) { if (vi[i] == str) { cout << i << endl; continue; } } } } return 0; }
以上是关于PAT乙级1044的主要内容,如果未能解决你的问题,请参考以下文章