PAT A1100 注意处理特殊情况

news/2024/12/22 10:56:50/

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<cstdio>
#include <string>
#include <iostream>
#include<math.h>
#include<map>
using namespace std;
char b[10] = {};
map<string,int> mp1;
map<string,int> mp2;
int main(){
int num;
string a[13] = {"tret","jan", "feb", "mar", "apr", "may", "jun", "jly","aug", "sep", "oct", "nov", "dec"};
string b[13] = {"tret","tam", "hel", "maa", "huh", "tou", "kes", "hei", "elo", "syy", "lok", "mer", "jou"};
for(int i=0;i<13;i++){
mp1[a[i]] = i;
mp2[b[i]] = i;
}
scanf("%d",&num);
for(int i=0;i<num;i++){
string s,s2;
cin>>s;
if( getchar() == ' ')
{
cin>>s2;
}
if('0'<=s[0]&&s[0]<='9'){
int l = s.length()-1;
int numR = 0;
for(int i=0;i<s.length();i++){
numR += (s[i]-'0')*pow(10, l--);
}
int low = numR%13;
int high = numR/13;
if(high==0){
cout <<a[low]<<"\n";
}else if(high!=0&&low==0){
cout<<b[high]<<"\n";
}else{
cout<<b[high]<<" "<<a[low]<<"\n";
}
}else{
if(s2.length()==0){
for(int i=0;i<13;i++){
if(s==a[i]){
printf("%d\n",mp1[a[i]]);
break;
}
if(s==b[i]){
printf("%d\n",mp2[b[i]]*13);
break;
}
}
}else{
int sum = mp2[s]*13+mp1[s2];
printf("%d\n",sum);
}
}
}
return 0;
}

http://www.ppmy.cn/news/579715.html

相关文章

【PAT-A1100】Mars Numbers(进制转换)

【题意】 是一个10进制和13进制转换的问题。 依次给出N(<100)个输入&#xff0c;可能是10进制数&#xff0c;也可能是13进制的表示&#xff08;取值为[0, 169)也就是13进制最多两位&#xff0c;但也可能为1位&#xff09; 0到12分别在13进制中对应 “tret, jan, feb, mar,…

Tsinsen A1100 乘法运算

http://oj.tsinsen.com/A1100 分析&#xff1a;格式比较坑&#xff0c;网页显示也不太好。大概是说都占4位&#xff0c;如果ab中b是两位数&#xff0c;两个乘出来的再分别对齐个位和十位。 代码&#xff1a; #include "cstdio"int main() {int a, b, c, d, e;scan…

【PAT甲级A1100】1100 Mars Numbers (20分)(c++)

1100 Mars Numbers (20分) 作者&#xff1a;CHEN, Yue 单位&#xff1a;浙江大学 代码长度限制&#xff1a;16 KB 时间限制&#xff1a;400 ms 内存限制&#xff1a;64 MB People on Mars count their numbers with base 13: Zero on Earth is called “tret” on Mars. The…

pat甲级A1100

作者&#xff1a;王是王小明&#xff0c;仅用来记录自己的学习型经历&#xff0c;转载请表明出处 Actually this coding is not difficult ,the logic is very simple.Because the data volume is small,so the use of the STL’s map directly to establish a mapping table,…

A1100.Mars Numbers

A1100.Mars Numbers //打表进制转换 //10进制转为13进制&#xff0c;只不过13进制的输出方式与常规形式不同&#xff0c;这里采用的是火星文。输入的数据最大只到169&#xff0c; //也就是说对应的13进制最多只有两位&#xff0c;所以不用使用数组存储每个转化后进制位&#x…

A1100 Mars Numbers

题目描述 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 hi…

PAT_A1100

AC代码&#xff1a; #include <iostream> #include <cstdio> #include <map> #include <string> #include <vector> using namespace std;enum v1{jan, feb, mar, apr, may, jun, jly, aug, sep, oct, nov, dec}; enum v2{tam, hel, maa, huh, t…

PAT 甲级 A1100

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 Earth is called “jan, feb, mar, apr, may, jun, jly, aug, sep, oct, nov, dec” on Mars, respectively.For t…