pat甲级A1100

news/2024/12/22 11:34:37/

作者:王是王小明,仅用来记录自己的学习型经历,转载请表明出处
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,the query can be directly.Readers need to pay attention to “%d%*c” this,use the “scanf” to intput later when the default “\n” with a newline.

#include <cstdio>
#include <iostream>
#include <string>
#include <map>using namespace std;string unitDigit[13] = {"tret","jan","feb","mar","apr","may","jun","jly","aug","sep","oct","nov","dec"};
string tenDigit[13] = {"tret", "tam", "hel", "maa", "huh", "tou", "kes","hei", "elo", "syy", "lok", "mer", "jou"};
string numToStr[170];
map<string,int> strToNum;void init()
{for(int i=0;i<13;i++){numToStr[i] = unitDigit[i];strToNum[unitDigit[i]] = i;numToStr[i*13] = tenDigit[i];strToNum[tenDigit[i]] = i*13;}for(int i=1;i<13;i++){for(int j=1;j<13;j++){string str = tenDigit[i] + " " + unitDigit[j];numToStr[i*13 + j] = str;strToNum[str] = i * 13 + j;  }}
}int main()
{init();int n;scanf("%d%%*c",&n);for(int i=0;i<n;i++){//getchar();string str;getline(cin,str);if(str[0]>='0' && str[0]<='9'){int num = 0;for(int i=0;i<str.length();i++){num = num * 10 + (str[i]-'0');}cout<< numToStr[num]<<endl;}else{cout<< strToNum[str]<<endl;}}return 0;
} 

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

相关文章

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…

PAT甲级 A1100

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, res…

PAT A1100

实质上没什么难的&#xff0c;体感表达的意思无非是将十进制数字转换为13进制&#xff0c;然后给出将数字替换成相应的字符串&#xff1b; 但是这道题的示例代码给出了所谓打表的新思路&#xff0c;之前没参加过ACM或者OJ比赛&#xff0c;也就没听说过&#xff1b;简单的来说就…

A1100 Mars Numbers [map映射]

貌似cin完之后&#xff1b;读入的光标实际上是停在cin读入的c的后面&#xff1b;这时如果是用cin.get或cin.getline或getchar之类的东西再读入&#xff0c;就会吃进c后面的回车&#xff1b;而如果用cin读入&#xff0c;因为cin本身是会略过回车读入的&#xff0c;所以对cin不会…

PAT A1100 解题思路 及 测试点 1 解决方法

首先注意容易错的地方&#xff0c;即 13 的整数倍转换为火星文时不要带最后的 tret 。 还要注意输入的字母有没有打错&#xff01;最好直接复制粘贴&#xff01;&#xff01;&#xff01; 测试点1涉及到 0 的转化&#xff0c;有这个错误的同学可以试一下。 第一种方法是自己…