PAT A1100 Mars Numbers ——满地黄花留不住 那一个赶考的书生

PAT A1100 Mars Numbers

  • 做了字符串和数字的双向映射,然后就是判断是数字还是字符串,然后做相应的转换或切割
  • 同样注意cin和getline同时使用时结尾回车的问题
  • 以及当数字是13的倍数时,火星文的个位0(tret)不输出,并处理空格和换行
  • 在这里插入图片描述

#include<iostream>
#include<string>
#include<unordered_map>

using namespace std;

string toMars1[] = {"tret", "jan", "feb", "mar", "apr", "may", "jun", "jly", "aug", "sep", "oct", "nov", "dec"};
string toMars2[] = {"tret", "tam", "hel", "maa", "huh", "tou", "kes", "hei", "elo", "syy", "lok", "mer", "jou"};
unordered_map<string,int> umap1,umap2;

int main(){

    int num;
    cin >> num;
    getchar();
    for(int i = 0;i < 13;i ++){
        umap1.insert({toMars1[i],i});
        umap2.insert({toMars2[i],i});
    }

    for(int i = 0;i < num;i ++){
        string tmp;
        getline(cin,tmp);
        if(tmp[0] <= '9' && tmp[0] >= '0'){
            int val = stoi(tmp);
            if(val / 13){
                cout << toMars2[val / 13];
                if(val % 13 == 0){
                    cout << endl;
                    continue;
                } else cout << ' ';
            }
            cout << toMars1[val % 13] << endl;
        }else{
            int pos = tmp.find(' ');
            if(pos != -1){
                cout << umap2[tmp.substr(0,pos)] * 13 + umap1[tmp.substr(pos + 1,-1)] << endl;
            }else cout << umap2[tmp] * 13 + umap1[tmp] << endl;
        }
    }
    return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值