码迷,mamicode.com
首页 > 其他好文 > 详细

PTA乙级 (*1044 火星数字 (20分))

时间:2020-02-04 00:25:01      阅读:79      评论:0      收藏:0      [点我收藏+]

标签:str   sep   ref   cpp   problems   getline   highlight   nbsp   etc   

1044 火星数字 (20分)

https://pintia.cn/problem-sets/994805260223102976/problems/994805279328157696

#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <cmath>
#include <algorithm>
using namespace std;
string str1[13]={"tret","jan","feb","mar","apr","may","jun","jly","aug","sep","oct","nov","dec"};
string str2[13]={"tret","tam","hel","maa","huh","tou","kes","hei","elo","syy","lok","mer","jou"};
string str;
void fun1(int n)
{
	if(n/13) cout<<str2[n/13];
	if((n/13)&&(n%13)) cout<<" ";
	if((n%13)||(n==0)) cout<<str1[n%13];
}
void fun2()
{
	string s1=str.substr(0,3),s2;
	if(str.length()>4) s2=str.substr(4,3);
	int t1=0,t2=0;
	for(int j=1;j<=12;j++)
	{
		if((s1==str1[j])||(s2==str1[j])) t2=j;
		if(s1==str2[j]) t1=j;
	}
	cout<<t1*13+t2;
}
int main()
{
	int N;
	cin>>N;
	getchar();
	for(int i=0;i<N;i++)
	{
		getline(cin,str);
		if(str[0]>=‘0‘&&str[0]<=‘9‘) fun1(stoi(str));
		else fun2();
		cout<<endl;
	}
	return 0;
}

  

 

PTA乙级 (*1044 火星数字 (20分))

标签:str   sep   ref   cpp   problems   getline   highlight   nbsp   etc   

原文地址:https://www.cnblogs.com/jianqiao123/p/12257931.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!