PATA1100题解

//
//  main.cpp
//  PATA1100
//
//  Created by Phoenix on 2018/2/22.
//  Copyright © 2018年 Phoenix. All rights reserved.
//

#include <iostream>
#include <cstdio>
#include <cstring>
#include <map>
#include <string>
using namespace std;

string month[13] = {"tret", "tam", "hel", "maa", "huh", "tou", "kes", "hei", "elo", "syy", "lok", "mer", "jou"};
string day[13] = {"tret", "jan", "feb", "mar", "apr", "may", "jun", "jly", "aug", "sep", "oct", "nov", "dec"};
map<string, int> mp1;
map<string, int> mp2;

void init() {
    for(int i = 0; i < 13; i++) {
        mp1[month[i]] = i;
    }
    for(int i = 0; i < 13; i++) {
        mp2[day[i]] = i;
    }
}
int main(int argc, const char * argv[]) {
    init();
    int n;
    scanf("%d ", &n);
    for(int i = 0; i < n; i++) {
        char str[10];
        gets(str);
        if(str[0] >= '0' && str[0] <= '9') {
            int num = 0;
            for(int j = 0; j < strlen(str); j++) {
                num = num * 10 + str[j] - '0';
            }
            if(num % 13 == 0) {
                cout << month[num / 13] << endl;
            }else {
                if(num / 13 == 0) cout << day[num] << endl;
                else cout << month[num / 13] << " " << day[num % 13] << endl;
            }
        } else if(strlen(str) > 4) {
            string a, b;
            int j = 0;
            while(str[j] != ' ') {
                a += str[j];
                j++;
            }
            j++;
            while(str[j] >= 'a' && str[j] <= 'z' && j < strlen(str)){
                b += str[j];
                j++;
            }
            //cout << mp1[a];
            int ans = mp1[a] * 13 + mp2[b];
            //cout << a << " " << b << " ";
            printf("%d\n", ans);
        } else {
            string a;
            int j = 0;
            while(str[j] >= 'a' && str[j] <= 'z' && j < strlen(str)) {
                a += str[j];
                j++;
            }
            printf("%d\n", mp1[a] * 13 + mp2[a]);
        }
    }
    return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值