pat 1100
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 (<). 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 <bits/stdc++.h> 2 using namespace std; 3 map<string,int>mp1; 4 map<string,int>mp2; 5 string s; 6 int l; 7 //mo 为余数,mar 为商 8 string mo[15]={"tret","jan", "feb", "mar", "apr", "may", "jun", "jly", "aug", "sep", "oct", "nov", "dec"}; 9 string mar[15]={"","tam", "hel", "maa", "huh", "tou", "kes", "hei", "elo", "syy", "lok", "mer", "jou"}; 10 void init() 11 { 12 for(int i =0;i<=12;i++){ 13 mp1[mar[i]] = i; 14 } 15 for(int i =1;i<=12;i++){ 16 mp2[mo[i]] = i; 17 } 18 } 19 void zifu(string s) 20 { 21 int ans = 0; 22 for(int i =0;s[i];i++){ 23 ans =ans*10+s[i]-'0'; 24 } 25 int x=ans/13;int y= ans%13; 26 if(x==0){ 27 cout<<mo[y]<<endl; 28 } 29 else{ 30 if(y==0){ 31 cout<<mar[x]<<endl;//如 : 13 :tam 后面没有tret 32 } 33 else{ 34 cout<<mar[x]<<" "<<mo[y]<<endl; 35 } 36 } 37 } 38 void isnum(string s){ 39 string s1,s2; 40 int p=0,q=0; 41 if(l<=3){//可能地球文字也可能火星文字 42 p=mp1[s]; 43 q=mp2[s]; 44 } 45 else{ 46 s1 =s.substr(0,3);//从0开始数3个 47 s2 =s.substr(4,3); 48 p =mp1[s1]; 49 q =mp2[s2]; 50 } 51 printf("%d\n",p*13+q); 52 } 53 int main() 54 { 55 56 57 int n; 58 scanf("%d",&n); 59 getchar(); 60 while(n--){ 61 init(); 62 getline(cin,s); 63 l =s.length(); 64 if(isdigit(s[0])){ 65 zifu(s); 66 } 67 else{ 68 isnum(s); 69 } 70 } 71 return 0; 72 }
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· go语言实现终端里的倒计时
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· ollama系列01:轻松3步本地部署deepseek,普通电脑可用
· 25岁的心里话
· 按钮权限的设计及实现
2018-09-18 zoj 4057
2018-09-18 zoj 4056
2018-09-18 zoj 4054
2018-09-18 zoj 4049