pat 1100 Mars Numbers(20 分)
20 PAT Numbers
2023-09-11 14:21:10 时间
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 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
1 #include <iostream> 2 #include <algorithm> 3 #include <cstdio> 4 #include <cstring> 5 #include <string> 6 #include <map> 7 #include <stack> 8 #include <vector> 9 #include <queue> 10 #include <set> 11 #define LL long long 12 #define INF 0x3f3f3f3f 13 using namespace std; 14 const int MAX = 30; 15 16 int n; 17 string s; 18 char s1[MAX][6] = {"tret", "jan", "feb", "mar", "apr", "may", "jun", "jly", "aug", "sep", "oct", "nov", "dec"}; 19 char s2[MAX][6] = {" ", "tam", "hel", "maa", "huh", "tou", "kes", "hei", "elo", "syy", "lok", "mer", "jou"}; 20 21 int my_pow(int x, int n) 22 { 23 int ans = 1; 24 while (n) 25 { 26 if (n & 1) ans *= x; 27 x *= x; 28 n >>= 1; 29 } 30 return ans; 31 } 32 33 int main() 34 { 35 // freopen("Date1.txt", "r", stdin); 36 scanf("%d", &n); 37 getchar(); 38 for (int i = 1; i <= n; ++ i) 39 { 40 getline(cin, s); 41 if (isalpha(s[0])) 42 { 43 int len = s.size(); 44 if (len >= 6) 45 { 46 char str1[6], str2[6]; 47 int a = 0, b = 0, ans = 0; 48 for (a, b; a < len; ++ a, ++ b) 49 { 50 if (s[a] == ' ') break; 51 str1[b] = s[a]; 52 } 53 str1[b] = '\0'; 54 ++ a, b = 0; 55 for (a, b; a < len; ++ a, ++ b) 56 str2[b] = s[a]; 57 str2[b] = '\0'; 58 for (int i = 0; i < 13; ++ i) 59 { 60 if (strcmp(s1[i], str2) == 0) 61 { 62 ans += i; 63 break; 64 } 65 } 66 for (int i = 1; i <= 13; ++ i) 67 { 68 if (strcmp(s2[i], str1) == 0) 69 { 70 ans += i * 13; 71 break; 72 } 73 } 74 printf("%d\n", ans); 75 } 76 else 77 { 78 char str1[10]; 79 for (int i = 0; i < len; ++ i) 80 str1[i] = s[i]; 81 str1[len] = '\0'; 82 bool flag = false; 83 for (int i = 0; i < 13; ++ i) 84 { 85 if (strcmp(str1, s1[i]) == 0) 86 { 87 flag = true; 88 printf("%d\n", i); 89 break; 90 } 91 } 92 if (flag) continue; 93 for (int i = 1; i < 13; ++ i) 94 { 95 if (strcmp(str1, s2[i]) == 0) 96 { 97 printf("%d\n", i * 13); 98 break; 99 } 100 } 101 } 102 } 103 else 104 { 105 int ans = 0, len = s.size(), t1, t2; 106 for (int i = 0, j = len - 1; i < len; ++ i, -- j) 107 ans += (s[i] - '0') * my_pow(10, j); 108 t1 = ans / 13, t2 = ans % 13; 109 if (ans <= 12) 110 printf("%s\n", s1[ans]); 111 else if (t2 == 0) 112 printf("%s\n", s2[t1]); 113 else 114 printf("%s %s\n", s2[t1], s1[t2]); 115 } 116 } 117 return 0; 118 }
相关文章
- python安装python-lzf包,报错lzf_module.c:3:20: fatal error: Python.h: No such file or directory
- 【PAT乙级】1054 求平均值 (20 分)
- 【PAT乙级】1043 输出PATest (20 分)
- 【PAT乙级】1038 统计同成绩学生 (20 分)
- 【PAT乙级】1029 旧键盘 (20 分)
- 【PAT乙级】1028 人口普查 (20 分)
- 【PAT乙级】1024 科学计数法 (20 分)
- 【PAT乙级】1092 最好吃的月饼 (20 分)
- 【PAT乙级】1089 狼人杀-简单版 (20 分)
- 【PAT乙级】1084 外观数列 (20 分)
- 【PAT乙级】1072 开学寄语 (20 分)
- 【PAT乙级】1062 最简分数 (20 分)
- 【PAT乙级】1002 写出这个数 (20 分)
- 分享20篇Linux入门教程
- FL studio 20简易入门教程 -- 第二篇 -- 菜单栏讲解(上)
- FL studio 20中那些“花里胡哨”的效果器(三)
- 【Linux】ubuntu 20无法打开终端的解决方法
- javascript创建函数的20种方式汇总
- 【MySQL】20-MySQL如何创建和管理表超详细汇总
- 20行代码实现电影评论情感分析
- PAT-PAT (Advanced Level) Practise 1001. A+B Format (20) 【二星级】
- pat 1092 To Buy or Not to Buy(20 分)
- pat 1041 Be Unique(20 分)
- pat 1120 Friend Numbers(20 分)
- 1073 多选题常见计分法 (20分)C语言
- maptalks 开发GIS地图(20)maptalks.three.13 - buildings-topcolor
- 王道数据结构 (20) 堆排序 基于二叉堆的排序