PAT_A 1100. Mars Numbers (20)
来源:互联网 发布:朝鲜姓氏 知乎 编辑:程序博客网 时间:2024/05/20 17: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、就是要懂题,最开始我就没读明白,英语能力待提高。
2、这道题很简单,主要是对字符串的处理,比如读取一行getchar() getline(),字符串拆分strtok()
#include<iostream>#include<string>#include<cstring>#include<cstdio>#include<map>using namespace std;map<string,int>m1={ {"tret",0}, {"jan",1}, {"feb",2}, {"mar",3}, {"apr",4}, {"may",5}, {"jun",6}, {"jly",7}, {"aug",8}, {"sep",9}, {"oct",10}, {"nov",11}, {"dec",12}, {"tam",13},//能够整除13的键值对 {"hel",26}, {"maa",39}, {"huh",52}, {"tou",65}, {"kes",78}, {"hei",91}, {"elo",104}, {"syy",117}, {"lok",130}, {"mer",143}, {"jou",156}};map<string,int>m2={ {"tam",1}, {"hel",2}, {"maa",3}, {"huh",4}, {"tou",5}, {"kes",6}, {"hei",7}, {"elo",8}, {"syy",9}, {"lok",10}, {"mer",11}, {"jou",12}};map<int,string>m3={ {0,"tret"}, {1,"jan"}, {2,"feb"}, {3,"mar"}, {4,"apr"}, {5,"may"}, {6,"jun"}, {7,"jly"}, {8,"aug"}, {9,"sep"}, {10,"oct"}, {11,"nov"}, {12,"dec"}};map<int,string>m4={ {1,"tam"}, {2,"hel"}, {3,"maa"}, {4,"huh"}, {5,"tou"}, {6,"kes"}, {7,"hei"}, {8,"elo"}, {9,"syy"}, {10,"lok"}, {11,"mer"}, {12,"jou"}};int main(){ int n=0; char tmp[110][30]; cin>>n; //老问题了,c++ primer plus上就专门说过这个问题,没想到在这与到了,要掌握这种读取行的方式 getchar(); string sttmp; for(int i=0;i<n;i++) { getline(cin,sttmp); memcpy(tmp[i],sttmp.c_str(),sttmp.length()+1); } for(int i=0;i<n;i++) { if(tmp[i][0]>='0'&&tmp[i][0]<='9') { int t=atoi(tmp[i]); if(t>=13) { cout<<m4.at(t/13); if(t%13!=0) cout<<" "<<m3.at(t%13)<<endl; else cout<<endl; } else if(t==0) { cout<<"tret"<<endl; } else { cout<<m3.at(t%13)<<endl; } }else { int it=0; //c语言的strtok字符串拆分挺好用的 char *t=strtok(tmp[i]," "); char *tt=NULL; if((tt=strtok(NULL," "))!=NULL) { it=13*m2.at(t)+m1.at(tt); }else { if(strcmp(t,"tam")==0) { it=13; } else//对于能整除13的直接使用高位key-value it=m1.at(t); } cout<<it<<endl; } } return 0;}
- PAT_A 1100. Mars Numbers (20)
- 1100. Mars Numbers (20)
- 1100. Mars Numbers (20)
- 1100. Mars Numbers (20)
- 1100. Mars Numbers (20)
- 1100. Mars Numbers (20)
- 1100. Mars Numbers (20)
- 1100. Mars Numbers (20)
- 1100. Mars Numbers (20)
- 1100. Mars Numbers (20)
- 1100. Mars Numbers (20)
- 1100. Mars Numbers (20)
- 1100. Mars Numbers (20)
- 1100. Mars Numbers (20)
- 1100. Mars Numbers (20)
- 1100. Mars Numbers (20)
- 1100. Mars Numbers (20)
- 1100. Mars Numbers (20)
- 润乾报表:动态改变填报更新数据的数据源
- python快速入门
- 我的榜样“杜拉拉”
- 虚拟按键
- java日期时间的处理与比较
- PAT_A 1100. Mars Numbers (20)
- 完全数
- 有关HTML
- 总结之浮动(页面3大布局之一)
- 成长之路——InfoQ视频心得笔记
- python字符串处理函数
- 如何识别图像边缘?
- 导入带公式excel的问题
- 第4章 注重实效的偏执