1100 Mars Numbers (20 分)(******)

60 篇文章 0 订阅
50 篇文章 0 订阅
设立数组对应会更方便,不要一个一个对应的打进去
string mar{13}= {jan, feb, mar, apr, may, jun, jly, aug, sep, oct, nov, dec}

我是怎么写出这么蠢得代码的啊啊啊啊啊,虽然AC但是太花时间了。

%*c  (*代表忽略输入)


	string b;
    stringstream ss(s);//加<sstream>头文件  将数组按空格分隔输出
    int ans=0;
    while(ss>>b) {
        ans += mp[b];
    }
#include <iostream>
#include <cstdio>
#include <map>
#include <sstream>
#include <string>
#include <cstring>
using namespace std;

int MarToEarth(string s)
{
    map<string,int>mp;
    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"] = 1*13;
    mp["hel"] = 2*13;
    mp["maa"] = 3*13;
    mp["huh"] = 4*13;
    mp["tou"] = 5*13;
    mp["kes"] = 6*13;
    mp["hei"] = 7*13;
    mp["elo"] = 8*13;
    mp["syy"] = 9*13;
    mp["lok"] = 10*13;
    mp["mer"] = 11*13;
    mp["jou"] = 12*13;
    string b;
    stringstream ss(s);
    int ans=0;
    while(ss>>b) {
        ans += mp[b];
    }
    printf("%d\n",ans);
}

int getN(string s)
{
    map<int,string>mp;

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

    int r = 0,a = 0;
    for(int i = 0;i<s.length();i++)
    {
        char name = s[i];
        a = s[i] - '0';
        r = r*10 + a;
    }
    if(r%13==0)
        cout<<mp[r/13 * 13]<<endl;
    else if(r>13)
        cout<<mp[r/13 * 13]<<" "<<mp[r%13]<<endl;
    else
        cout<<mp[r%13]<<endl;
    return r;
}

int main()
{
    int n;
    scanf("%d%*c",&n);
    for(int i =0;i<n;i++)
    {
        string s1;
        getline(cin,s1);
        if(s1[0]>='0' && s1[0] <='9')
            getN(s1);
        else
            MarToEarth(s1);
    }



    return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值