1100. Mars Numbers (20)【字符串处理】——PAT (Advanced Level) Practise

题目信息

1100. Mars Numbers (20)

时间限制400 ms

内存限制65536 kB

代码长度限制16000 B

People on Mars count their numbers with base 13:

Zero on Earth is called “tret” on Mars.

The numbers 1 to 12 on Earch 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

解题思路

字符串处理,细心即可

AC代码

#include <cstdio>
#include <string>
#include <cstring>
#include <map>
using namespace std;
char str1[13][5] = {"tret", "jan", "feb", "mar", "apr", "may", "jun", "jly", "aug", "sep", "oct", "nov", "dec"};
char str2[13][5] = {"tret", "tam", "hel", "maa", "huh", "tou", "kes", "hei", "elo", "syy", "lok", "mer", "jou"};
int main()
{
    map<int, string> iskv1, iskv2;
    map<string, int> sikv1, sikv2;
    for (int i = 0; i <= 12; ++i){
        iskv1[i] = str1[i];
        iskv2[i] = str2[i];
        sikv1[str1[i]] = i;
        sikv2[str2[i]] = i;
    }
    int n, a;
    char s[1000], s2[5];
    scanf("%d", &n);
    gets(s);
    for (int i = 0; i < n; ++i){
        gets(s);
        if (s[0] >= ‘0‘ && s[0] <= ‘9‘){
            sscanf(s, "%d", &a);
            if (a > 12) {
                if (a%13 == 0) printf("%s\n", iskv2[a/13].c_str());
                else printf("%s %s\n", iskv2[a/13].c_str(), iskv1[a%13].c_str());
            }else{
                printf("%s\n", iskv1[a].c_str());
            }
        }else{
            char *p = strtok(s, " ");
            char *p2 = strtok(NULL, " ");
            if (p && p2) {
                a = sikv2[p] * 13;
                a += sikv1[p2];
            }else if (p){
                a = sikv2[p] * 13;
                a += sikv1[p];
            }
            printf("%d\n", a);
        }
    }
    return 0;
}
时间: 2024-10-17 10:57:11

1100. Mars Numbers (20)【字符串处理】——PAT (Advanced Level) Practise的相关文章

PAT甲级题解-1100. Mars Numbers (20)-字符串处理

没什么好说的,注意字符串的处理,以及当数字是13的倍数时,只需高位叫法的单词.比如26,是"hel",而不是"hel tret". 代码: #include <iostream> #include <cstdio> #include <algorithm> #include <map> #include <string> #include <string.h> using namespace s

1093. Count PAT&#39;s (25)【计数】——PAT (Advanced Level) Practise

题目信息 1093. Count PAT's (25) 时间限制120 ms 内存限制65536 kB 代码长度限制16000 B The string APPAPT contains two PAT's as substrings. The first one is formed by the 2nd, the 4th, and the 6th characters, and the second one is formed by the 3rd, the 4th, and the 6th c

1069. The Black Hole of Numbers (20)【模拟】——PAT (Advanced Level) Practise

题目信息 1069. The Black Hole of Numbers (20) 时间限制100 ms 内存限制65536 kB 代码长度限制16000 B For any 4-digit integer except the ones with all the digits being the same, if we sort the digits in non-increasing order first, and then in non-decreasing order, a new n

PAT (Advanced Level) 1100. Mars Numbers (20)

简单题. #include<cstdio> #include<cstring> #include<cmath> #include<vector> #include<map> #include<queue> #include<stack> #include<algorithm> using namespace std; char a[20][6]={ "tret","jan"

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 Earch is called "jan, feb, mar, apr, may, jun, jly, aug, sep, oct, nov, dec" on Mars, respectively. For the next higher dig

1027. Colors in Mars (20)【进制转换】——PAT (Advanced Level) Practise

题目信息 1027. Colors in Mars (20) 时间限制400 ms 内存限制65536 kB 代码长度限制16000 B People in Mars represent the colors in their computers in a similar way as the Earth people. That is, a color is represented by a 6-digit number, where the first 2 digits are for Re

1084. Broken Keyboard (20)【字符串操作】——PAT (Advanced Level) Practise

题目信息 1084. Broken Keyboard (20) 时间限制200 ms 内存限制65536 kB 代码长度限制16000 B On a broken keyboard, some of the keys are worn out. So when you type some sentences, the characters corresponding to those keys will not appear on screen. Now given a string that

1077. Kuchiguse (20)【字符串处理】——PAT (Advanced Level) Practise

题目信息 1077. Kuchiguse (20) 时间限制100 ms 内存限制65536 kB 代码长度限制16000 B The Japanese language is notorious for its sentence ending particles. Personal preference of such particles can be considered as a reflection of the speaker's personality. Such a prefere

1050. String Subtraction (20)【字符串处理】——PAT (Advanced Level) Practise

题目信息 1050. String Subtraction (20) 时间限制10 ms 内存限制65536 kB 代码长度限制16000 B Given two strings S1 and S2, S = S1 - S2 is defined to be the remaining string after taking all the characters in S2 from S1. Your task is simply to calculate S1 - S2 for any giv