栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > C/C++/C#

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

C/C++/C# 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

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);
        }
    }
}
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/665626.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号