1100. Mars Numbers (20)【字符串处理】——PAT (Advanced Level) Practise
来源:互联网 发布:复方肾炎片价格淘宝 编辑:程序博客网 时间:2024/04/29 07:05
题目信息
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;}
- 1100. Mars Numbers (20)【字符串处理】——PAT (Advanced Level) Practise
- PAT (Advanced Level) Practise 1100 Mars Numbers (20)
- PAT (Advanced Level) Practise 1100 Mars Numbers (20)
- 【PAT】【Advanced Level】1100. Mars Numbers (20)
- 1023. Have Fun with Numbers (20)【字符串操作】——PAT (Advanced Level) Practise
- PAT-PAT (Advanced Level) Practise 1100 Mars Numbers (20)【二星级】
- 1031. Hello World for U (20)【字符串处理】——PAT (Advanced Level) Practise
- 1035. Password (20)【字符串处理】——PAT (Advanced Level) Practise
- 1050. String Subtraction (20)【字符串处理】——PAT (Advanced Level) Practise
- 1077. Kuchiguse (20)【字符串处理】——PAT (Advanced Level) Practise
- 1027. Colors in Mars (20)【进制转换】——PAT (Advanced Level) Practise
- PAT (Advanced Level) 1100. Mars Numbers (20) 解题报告
- 1027. Colors in Mars (20) @ PAT (Advanced Level) Practise
- PAT (Advanced Level) Practise 1027 Colors in Mars (20)
- PAT (Advanced Level) Practise 1027 Colors in Mars (20)
- 1069. The Black Hole of Numbers (20)【模拟】——PAT (Advanced Level) Practise
- 1060. Are They Equal (25)【字符串处理】——PAT (Advanced Level) Practise
- 1082. Read Number in Chinese (25)【字符串处理】——PAT (Advanced Level) Practise
- Combination Sum III
- 2016"百度之星" - 资格赛(Astar Round1) Problem D 简单题
- 淘宝物流mysql slave数据丢失详细原因
- 查看Oracle数据库版本
- 火狐浏览器对于html()方法的支持性
- 1100. Mars Numbers (20)【字符串处理】——PAT (Advanced Level) Practise
- Linux Namespace
- Fragment和ViewPager实现底部导航栏
- Android学习笔记十一:Android 中关于 【Cursor】 类的介绍
- rhel 7.2 kickstart 编辑注意
- 1101. Quick Sort (25)【快排】——PAT (Advanced Level) Practise
- 错误集棉
- Dijkstra最短路
- nodejs后台文件上传模块connect-multiparty