1100. Mars Numbers (20)
来源:互联网 发布:路由器性能测试软件 编辑:程序博客网 时间:2024/06/05 15:11
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:4295elo novtamSample Output:
hel marmay11513
需要注意的地方:
1.不管tret出现在十位还是百位,都不需要打印
2.读入的事字符串时,需要注意tret的长度是4
笔记:
1、int t=atoi(s.c_str()); //string转int
2、getline(cin,s);//读取一行作为字符串
ac代码:
#include <iostream>#include <algorithm>#include <cstdio>#include <cstdlib>#include <string>#include <map>using namespace std;int main(){ //freopen("in.txt","r",stdin); string a[20]={"xxxx","tam", "hel", "maa", "huh","tou","kes","hei","elo","syy","lok","mer","jou"}; string b[20]={"tret","jan", "feb", "mar", "apr","may", "jun", "jly", "aug", "sep", "oct", "nov", "dec"}; int N; cin>>N; getchar();//吸收 while(N--) { string s; getline(cin,s);//读入一行 if(s[0]>='0'&&s[0]<='9')//读入数字 { int t=atoi(s.c_str());//string -> int int t1=t/13; int t2=t%13; if(t1==0) { cout<<b[t2]<<endl; } else if(t2==0) { cout<<a[t1]<<endl; } else { cout<<a[t1]<<' '<<b[t2]<<endl; } } else//读入字符 { if(s.length()>3) { int flag=0; if(s.length()==8) flag=1; int sum=0; string s1=s.substr(0,3);//起点和长度 string s2; if(flag==0) s2=s.substr(4,3); else s2=s.substr(4,4); for(int i=1;i<=12;i++) { if(a[i]==s1) { sum+=13*i; break; } } for(int i=1;i<=12;i++) { if(b[i]==s2) { sum+=i; break; } } printf("%d\n",sum); } else { for(int i=1;i<=12;i++) { if(a[i]==s) { printf("%d\n",13*i); break; } } for(int i=0;i<=12;i++) { if(b[i]==s) { printf("%d\n",i); break; } } } } } return 0;}
- 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)
- Java学习之数据库连接
- 使用jsp编写的验证码(工具类)
- MiniGUI体系结构之一
- 微信小程序 音乐播放(十三)
- 关于printk可变参数
- 1100. Mars Numbers (20)
- Highcharts图表无法显示
- 一键生成UGUI艺术字体
- 深度学习学习资料
- android项目中引入CoordinatorLayout控件问题总结
- 接口错误日志查询(SRT_UTIL)
- Nginx使用limit_req_zone对同一IP访问进行限流
- IDEA国际化文件中文乱码的解决办法
- KMP+dp NOI2014 动物园(PS:不是官方做法)