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). 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

满分代码:

#include "iostream"

#include "string"

#include "map"

using namespace std;

string low_digit[13]={"tret","jan","feb","mar","apr","may","jun","jly","aug","sep","oct","nov","dec"};

string up_digit[13]={

    "tret","tam","hel","maa","huh","tou","kes","hei","elo","syy","lok","mer","jou"

};

string NumToS[170];

int main(){

    int n;

    scanf("%d%*c",&n);

    map<string,int> mp;

    for (int i=0;i<13; i++) {

        NumToS[i]=low_digit[i];

        mp[low_digit[i]]=i;

        NumToS[i*13]=up_digit[i];

        mp[up_digit[i]]=i*13;

    }

    for (int i=1; i<13; i++) {

        for (int j=1; j<13; j++) {

            NumToS[i*13+j]=up_digit[i]+" "+low_digit[j];

            mp[up_digit[i]+" "+low_digit[j]]=i*13+j;

        }

    }

    for (int i=0; i<n; i++) {

        string input;

        getline(cin,input);

        if (input[0]>='0'&&input[0]<='9') {

            int Num=0;

            for (int i=0; i<input.length(); i++) {

                Num=Num*10+input[i]-'0';

            }

            cout << NumToS[Num];

            if (i!=n-1) {

                printf("\n");

            }

        }

        else{

            cout << mp[input];

            if (i!=n-1) {

                printf("\n");

            }

        }

    } 

}

反思:

熟悉map之后就会运用了,做过后面的题再过来看十分简单

发布了14 篇原创文章 · 获赞 0 · 访问量 142

猜你喜欢

转载自blog.csdn.net/Yanhaoming1999/article/details/102755591