PAT甲1100 Mars Numbers(20 分)

#include <string.h>
#include <stdio.h>
#include <vector>
#include <queue>
#include <algorithm>
#include <map>
#include <string>
#include <iostream>
#include <math.h>
using namespace std;

map<string,int> mp;

char A[20][5]={"tret", "jan","feb","mar","apr","may","jun","jly","aug","sep","oct","nov","dec"};
char B[20][5]={"","tam","hel","maa","huh","tou","kes","hei","elo","syy","lok","mer","jou"};

void init()
{
    mp["tret"]=0;
    mp["jan"]=1;
    mp["feb"]=2;
    mp["mar"]=3;
    mp["apr"]=4;
    mp["may"]=5;
    mp["jun"]=6;
    mp["jly"]=7;
    mp["aug"]=8;
    mp["sep"]=9;
    mp["oct"]=10;
    mp["nov"]=11;
    mp["dec"]=12;
    mp["tam"]=13*1;
    mp["hel"]=13*2;
    mp["maa"]=13*3;
    mp["huh"]=13*4;
    mp["tou"]=13*5;
    mp["kes"]=13*6;
    mp["hei"]=13*7;
    mp["elo"]=13*8;
    mp["syy"]=13*9;
    mp["lok"]=13*10;
    mp["mer"]=13*11;
    mp["jou"]=13*12;
}

int N;

void to13(string str)
{
    string result1="";
    string result2="";
    int number=0;
    for(int i=0;i<str.length();i++)
    {
        number=number*10+str[i]-'0';
    }
    if(number==0)printf("%s\n",A[0]);
    else
    {
        int step=0;
        while(number>0)
        {
            int pop=number%13;
            number/=13;
            if(step==0)
            {
                if(pop!=0)
                {
                    result1=A[pop];
                }
            }
            else
            {
                result2=B[pop];
            }
            step++;
        }
        if(result2.length()==0)
        {
            cout<<result1<<endl;
        }
        else if(result1.length()==0)
        {
            cout<<result2<<endl;
        }
        else
        {
            cout<<result2<<" "<<result1<<endl;
        }
    }
}

void to10(string str)
{
    int k=-1;
    string temp1,temp2;
    for(int i=0;i<str.length();i++)
    {
        if(str[i]==' ')
        {
            k=i;
            break;
        }
    }
    if(k!=-1)
    {
        temp1=str.substr(0,k);
        temp2=str.substr(k+1,str.length()-k);
    }
    else
    {
        temp1=str;
    }
    int num1=0,num2=0;
    if(mp.find(temp1)!=mp.end())
    {
        num1=mp[temp1];
    }
    if(mp.find((temp2))!=mp.end())
    {
        num2=mp[temp2];
    }
    cout<<num1+num2<<endl;
}



int main()
{
    init();
    scanf("%d",&N);
    getchar();
    string str;
    for(int i=0;i<N;i++)
    {
        getline(cin,str);
        if(str[0]>='0'&&str[0]<='9')
        {
            to13(str);
        }
        else
        {
            to10(str);
        }
    }
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值