首页 > 编程语言 >PAT (Advanced Level)_1100 Mars Numbers (20分)(C++_模拟)

PAT (Advanced Level)_1100 Mars Numbers (20分)(C++_模拟)

时间:2023-06-20 10:05:12浏览次数:58  
标签:PAT elo temp Level int C++ Mars Earth nov


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 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

Process

如果你的第2、4测试点一直过不去,请试一下13转火星文是不是tam。

Code

#include<bits/stdc++.h>
using namespace std;
int n;
string gewei[] = { "tret", "jan", "feb", "mar", "apr", "may", "jun", "jly", "aug", "sep", "oct", "nov", "dec" };
string shiwei[] = { "","tam", "hel", "maa", "huh", "tou", "kes", "hei", "elo", "syy", "lok", "mer", "jou" };
int main()
{
	cin >> n;
	string temp;
	char a;
	getchar();
	for (int i = 0; i < n; i++) {
		getline(cin, temp);
		if (temp[0]<='9'&&temp[0]>='0')//数字
		{
			int tint = stoi(temp);
			cout << (tint / 13 != 0 ? shiwei[tint / 13] : "") << ((tint / 13 != 0 && tint % 13 != 0) ? " " : "") << ((tint % 13 != 0 || tint == 0) ? gewei[tint % 13] : "") << endl;
		}
		else
		{
			int t1 = 0, t2 = 0;
			string s1 = temp.substr(0, 3), s2 = "";
			if (temp.size() > 4)
				s2 = temp.substr(4, 3);
			for (int j = 1; j < 13; j++) {
				if (s1 == gewei[j] || s2 == gewei[j])
					t2 = j;
				if (s1 == shiwei[j])
					t1 = j;
			}
			cout << t1 * 13 + t2 << endl;
		}
	}
	return 0;
}


标签:PAT,elo,temp,Level,int,C++,Mars,Earth,nov
From: https://blog.51cto.com/u_16165815/6520492

相关文章

  • PAT_Advanced Level_1080 Graduate Admission(C++_模拟_快排_卡常)
    Itissaidthatin2011,thereareabout100graduateschoolsreadytoproceedover40,000applicationsinZhejiangProvince.Itwouldhelpalotifyoucouldwriteaprogramtoautomatetheadmissionprocedure.Eachapplicantwillhavetoprovidetwograd......
  • 数据结构代码整理_基于邻接表存储结构的有向图的实现(C++)
    目录RequirementsDebuggingEnvironmentChatCode1.graph.h2.test.cppRequirements       基于邻接表存储结构实现有向图的典型操作(构造、析构、增加顶点、删除顶点、增加弧、删除弧,查找一个顶点、判空、判满、图中顶点个数、邻接表中指定顶点的第一个邻接顶点、深度优先......
  • CCF_201912-2 回收站选址(C++_暴力_枚举)
    思路本来想用dfs来着,有垃圾的地方就标一后来看到数的大小为,数量却只有就果断暴力了…Code#include<bits/stdc++.h>//暴力枚举usingnamespacestd;typedeflonglongll;llx[1010],y[1010],num[1010],score[1010],ans[10];intmain(){ intn; cin>>n; for(inti=......
  • PTA_乙级_1002 写出这个数(C++_模拟)
    读入一个正整数n,计算其各位数字之和,用汉语拼音写出和的每一位数字。输入格式:每个测试输入包含1个测试用例,即给出自然数的值。这里保证小于。输出格式:在一行内输出n的各位数字之和的每一位,拼音数字间有1空格,但一行中最后一个拼音数字后没有空格。输入样例:1234567890987654......
  • 呼叫中心的离散事件模拟(C++_模拟)
    题目       模拟网上书店的电话接待台接电话(离散事件)的过程。用户在打电话咨询时,先输入自己的标识(如姓名或会员号),然后进入排队等待被接听电话。xauat服务人员会根据该用户在书店已购买书籍的累计消费情况对拨入的电话进行排序。累计消费超过3000元的为1类用户,最先得......
  • 逆波兰式求值(C++_模拟)
    题目       将中缀表达式翻译成后缀表达式(逆波兰表达式)时,可以去掉中缀表达式中出现的括号,简化表达式。如中缀表达式“(2+3)6”被转成后缀表达式“23+6”后,可以借助于栈对表达式求值,完成运算。规则大致如下:       遇到操作数,则入栈;       遇到二元运算符,则......
  • P1203 [USACO1.1]坏掉的项链Broken Necklace(C++_模拟_暴力枚举_优化)
    题目描述你有一条由n个红色的,白色的,或蓝色的珠子组成的项链,珠子是随意安排的。这里是n=29的两个例子:第一和第二个珠子在图片中已经被作记号。图片A中的项链可以用下面的字符串表示:brbrrrbbbrrrrrbrrbbrbbbbrrrrb假如你要在一些点打破项链,展开成一条直线,然后从一端开始收集......
  • P1582 倒水(C++_数论_进制)
    题目描述一天,CC买了N个容量可以认为是无限大的瓶子,开始时每个瓶子里有1升水。接着~~CC发现瓶子实在太多了,于是他决定保留不超过K个瓶子。每次他选择两个当前含水量相同的瓶子,把一个瓶子的水全部倒进另一个里,然后把空瓶丢弃。(不能丢弃有水的瓶子)显然在某些情况下CC无法达到目标,比......
  • P1478 陶陶摘苹果(升级版)(C++_贪心)
    题目描述又是一年秋季时,陶陶家的苹果树结了n个果子。陶陶又跑去摘苹果,这次他有一个a公分的椅子。当他手够不着时,他会站到椅子上再试试。这次与NOIp2005普及组第一题不同的是:陶陶之前搬凳子,力气只剩下s了。当然,每次摘苹果时都要用一定的力气。陶陶想知道在s<0s<0之前最多......
  • CCF_201612-4 压缩编码(C++_区间DP)
    问题描述       给定一段文字,已知单词a1,a2,…,an出现的频率分别t1,t2,…,tn。可以用01串给这些单词编码,即将每个单词与一个01串对应,使得任何一个单词的编码(对应的01串)不是另一个单词编码的前缀,这种编码称为前缀码。使用前缀码编码一段文字是指将这段文字中的每......