您的位置:首页 > 其它

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;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: