PAT (Advanced Level) Practise 1100 Mars Numbers (20)
2017-06-30 14:11
453 查看
1100. Mars Numbers (20)
时间限制400 ms
内存限制
65536 kB
代码长度限制
16000 B
判题程序
Standard
作者
CHEN, Yue
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
题意:给你新的表示数字的方法,用这个方法表示一个数
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <vector>
#include <bitset>
using namespace std;
#define LL long long
const int INF = 0x3f3f3f3f;
string s[20]={"tret","jan","feb","mar","apr","may","jun","jly","aug","sep","oct","nov","dec"};
string a[20]={"","tam","hel","maa","huh","tou","kes","hei","elo","syy","lok","mer","jou"};
map<string,int>ss,aa;
char ch[1000];
int main()
{
for(int i=0;i<13;i++) ss[s[i]]=i,aa[a[i]]=i;
int t;
scanf("%d",&t);
getchar();
while(t--)
{
gets(ch);
int len=strlen(ch);
if(ch[0]>='0'&&ch[0]<='9')
{
int k=0;
for(int i=0;i<len;i++) k=k*10+ch[i]-'0';
if(k==0) cout<<s[0];
else
{
if(k/13) cout<<a[k/13];
if(k%13)
{
if(k/13) cout<<" ";
cout<<s[k%13];
}
cout<<endl;
}
}
else
{
ch[len]=' ';ch[++len]='\0';
string k="";
int ans=0;
for(int i=0;i<len;i++)
{
if(ch[i]!=' ') k+=ch[i];
else
{
if(ss[k]) ans+=ss[k];
else ans+=aa[k]*13;
k="";
}
}
printf("%d\n",ans);
}
}
return 0;
}
相关文章推荐
- PAT (Advanced Level) Practise 1100 Mars Numbers (20)
- PAT-PAT (Advanced Level) Practise 1100 Mars Numbers (20)【二星级】
- PAT (Advanced Level) 1100. Mars Numbers (20)
- PAT (Advanced Level) 1100. Mars Numbers (20) 解题报告
- PAT advanced level 练习集 1100. Mars Numbers (20)
- 【PAT】【Advanced Level】1100. Mars Numbers (20)
- PAT (Advanced Level) Practise 1001. A+B Format (20)
- PAT (Advanced Level) Practise 1015. Reversible Primes (20) 素数筛法 进制转换
- PAT-PAT (Advanced Level) PractiseBe Unique (20) 【一星级】
- 浙大PAT (Advanced Level) Practise 1001 A+B Format (20)
- PAT (Advanced Level) Practise 1108 Finding Average (20)
- PAT (Advanced Level) Practise 1001 A+B Format (20)
- 1015. Reversible Primes (20) ——PAT (Advanced Level) Practise
- PAT (Advanced Level) Practise 1073 Scientific Notation (20)
- PAT (Advanced Level) Practise 1112 Stucked Keyboard (20)
- PAT (Advanced Level) Practise 1128 N Queens Puzzle (20)
- 1088. Rational Arithmetic (20)——PAT (Advanced Level) Practise
- 1104. Sum of Number Segments (20)【数学题】——PAT (Advanced Level) Practise
- PAT-PAT (Advanced Level) Practise A+B and C (64bit) (20) 【二星级】
- 1031. Hello World for U (20)【字符串处理】——PAT (Advanced Level) Practise