PAT (Advanced Level) Practice 1100 Mars Numbers (20 分)

PAT (Advanced Level) Practice 1100 Mars Numbers (20 分),第1张

PAT (Advanced Level) Practice 1100 Mars Numbers (20 分)

People on Mars count their numbers with base 13:

  • Zero on Earth is called “tret” on Mars.
  • The numbers 1 to 12 on Earth is called “jan, feb, mar, apr, may, jun, jly, aug, sep, oct, nov, dec” on Mars, respectively.
    For the next higher digit, Mars people name the 12 numbers as “tam, hel, maa, huh, tou, kes, hei, elo, syy, lok, mer, jou”, respectively.
  • For examples, the number 29 on Earth is called “hel mar” on Mars; and “elo nov” on Mars corresponds to 115 on Earth. In order to help communication between people from these two planets, you are supposed to write a program for mutual translation between Earth and Mars number systems.
Input Specification:

Each input file contains one test case. For each case, the first line contains a positive integer N ( < 100 ) N (<100) N(<100). Then N lines follow, each contains a number in [0, 169), given either in the form of an Earth number, or that of Mars.

Output Specification:

For each number, print in a line the corresponding number in the other language.

Sample Input:
4
29
5
elo nov
tam
Sample Output:
hel mar
may
115
13
AC code
#include
#include
#include
#include
using namespace std;

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

void outputMars(string s){
    int k1,k2;
    int n = stoi(s);
    k1 = n/13;
    k2 = n%13;
    
    if (k1==0) cout << low[k2] << endl;
    else if(k2==0) cout << high[k1-1] << endl;
    else
        cout << high[k1-1] <<" " << low[k2] << endl;
}

int getHighNum(string s){
    for(int i=0;i<12;i++){
        if(s==high[i]) return i+1;
    }
    return 0;
}

int getLowNum(string s){
    for(int i=0;i<13;i++){
        if(s==low[i]) return i;
    }
    return 0;
}

void outputNums(string s){
    int k1{0},k2{0},n{0};

    if(s.length()==7){
        k1 = getHighNum(s.substr(0,3));
        k2 = getLowNum(s.substr(4,3));
    }
    else{
        k1 = getHighNum(s);
        k2 = getLowNum(s);
    }
    n = 13*k1+k2;
    cout << n <> n;
    getchar();
    while(n--){
        string s;
        getline(cin,s);
        if(isdigit(int(s[0]))){
            outputMars(s);
        }
        else{
            outputNums(s);
        }
    }
}

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/zaji/5670895.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-12-16
下一篇2022-12-16

发表评论

登录后才能评论

评论列表(0条)

    保存