PAT Advanced 1100 Mars Numbers (20 )

题目描述

在这里插入图片描述

Input Specification:

在这里插入图片描述

Output Specification:

在这里插入图片描述

Sample Input:

在这里插入图片描述

Sample Output:

在这里插入图片描述

解题思路

一度怀疑我的语文阅读理解能力。。tam是13竟然是因为0不输出。。我一直以为是13-24是用高进制的数表示。。知道真相的我气到昏厥。。

Code

  • AC代码
#include<bits/stdc++.h>
using namespace std;
string unit1[] = {"tret", "jan", "feb", "mar", "apr", "may", "jun", "jly", "aug", "sep", "oct", "nov", "dec"};
string unit2[] = {"tret", "tam", "hel", "maa", "huh", "tou", "kes", "hei", "elo", "syy", "lok", "mer", "jou"};
void earth2mars(string str){
	int number = stoi(str);
	if(number < 13) {
		cout << unit1[number] << '\n';
	} else {
		cout << unit2[number/13];
		if(number%13) {
			cout << " " << unit1[number%13];
		}
		cout << '\n';
	}
}

void mars2earth(string str) {
	int res = 0;
	string tem1 = str, tem2 = "";
	int spaceIndex = str.find(' ');
	if(spaceIndex != -1) {
		tem1 = str.substr(0, spaceIndex);
		tem2 = str.substr(spaceIndex+1, str.length()-spaceIndex-1);
	}
	for(int i = 0; i<13; i++) {
		if(tem1 == unit1[i]) {
			res = i;
			break;
		}
		else if(tem1 == unit2[i]) {
			res = i*13;
			if(tem2.length()) {
				for(int j = 0; j<13; j++) {
					if(tem2 == unit1[j]) {
						res += j;
					}
				}
			} 
			break;
		}
	}
	cout << res << '\n';
}
int main() {
	//freopen("in.txt", "r", stdin);
	int N;
	cin >> N;
	getchar();
	string temp;
	for(int i = 0; i<N; i++) {
		getline(cin, temp);
		if(temp[0]>='0' && temp[0]<='9') {
			earth2mars(temp);
		} else {
			mars2earth(temp);
		}
	}
	
	return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值