1044. 火星数字(20)

火星人是以13进制计数的:

地球人的0被火星人称为tret。
地球人数字1到12的火星文分别为:jan, feb, mar, apr, may, jun, jly, aug, sep, oct, nov, dec。
火星人将进位以后的12个高位数字分别称为:tam, hel, maa, huh, tou, kes, hei, elo, syy, lok, mer, jou。
例如地球人的数字“29”翻译成火星文就是“hel mar”;而火星文“elo nov”对应地球数字“115”。为了方便交流,请你编写程序实现地球和火星数字之间的互译。

输入格式:

输入第一行给出一个正整数N(<100),随后N行,每行给出一个[0, 169)区间内的数字 —— 或者是地球文,或者是火星文。

输出格式:

对应输入的每一行,在一行中输出翻译后的另一种语言的数字。

输入样例:
4
29
5
elo nov
tam
输出样例:
hel mar
may
115
13

/////////////////////////
这题实在太麻烦了,细节很多。而且注意输入的数字是[0, 169),我一开始看成了0~100,几个测试点一直通不过。。
//////////////////

#include <iostream>
#include "string.h"
using namespace std;

int main()
{
    string gewei[13] = {"tret", "jan", "feb", "mar", "apr", "may", "jun", "jly", "aug", "sep", "oct", "nov", "dec"};
    string shiwei[12] = {"tam", "hel", "maa", "huh", "tou", "kes", "hei", "elo", "syy", "lok", "mer", "jou"};
    int n;
    cin>>n;


    int flag=0;
    int g,s;

    int j=0;

    for(int i=0;i<n;i++){
        //cin.get(str);
        char str[10]={0};
        j=0;
        flag=0;

        cin>>str[0] ;
        while(str[j]!='\n'){
            j++;
            cin.get(str[j]);
        }
            //cin>>str;
        //cout<<str<<endl;
        int num=0;
        if(str[0]>='0' && str[0]<='9'){
            if(str[2]>='0' && str[2]<='9'){
                num = (str[0] - '0')*100 + (str[1]-'0')*10 + str[2]-'0';
            }
            else if(str[1]>='0' && str[1]<='9')
                num = (str[0]-'0')*10 + str[1]-'0';
            else
                num = str[0] - '0';
            flag=1;
        }
        //else if(str[0]>='a' && str[0]<='z')
        //cout<<num<<endl;
        if(flag==1){
            s = num/13;
            g = num%13;
            if(s==0)
                cout<<gewei[g]<<endl;
            else if(g==0)
                cout<<shiwei[s-1]<<endl;
            else
                cout<<shiwei[s-1]<<" "<<gewei[g]<<endl;
        }
        else{
            int k=0;
            //if(str.length() > 4)
            char shi[4]={0},ge[4]={0};

            if(str[5]>='a' && str[5]<='z')
            {
                for(int i=0;i<3;i++)
                    shi[i] = str[i];
                for(int i=0;i<3;i++)
                    ge[i] = str[i+4];
            }
            else //if(str.length()<=3)
            {
                for(int i=0;i<3;i++)
                    ge[i] = str[i];
            }
            for(int i=0;i<12;i++){
                if(shi==shiwei[i]){
                    k += (i+1)*13;
                    break;
                }
            }
            for(int i=0;i<13;i++){
                if(ge==gewei[i]){
                    k += i;
                    break;
                }
                if(ge==shiwei[i]){
                    k += (i+1)*13;
                    break;
                }
            }
            cout<<k<<endl;
        }
    }

    return 0;
}

猜你喜欢

转载自blog.csdn.net/annazzz/article/details/77389250
今日推荐