码迷,mamicode.com
首页 > 其他好文 > 详细

PAT乙级1044

时间:2020-04-25 19:10:29      阅读:48      评论:0      收藏:0      [点我收藏+]

标签:git   ==   ++   c代码   init   看到了   ios   names   地球   

自己写的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

标签:git   ==   ++   c代码   init   看到了   ios   names   地球   

原文地址:https://www.cnblogs.com/ZJU-LOSER/p/12774407.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!