1100 Mars Numbers

本文介绍了一个使用C++编写的程序,该程序能够将输入的月份名称转换为对应的数字或者将数字转换为月份名称,并支持特定格式的日期字符串的转换。通过对输入的不同形式进行判断和处理,实现了灵活的日期格式转换功能。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

#include<iostream>
#include<string>
#include<bits/stdc++.h>
using namespace std;
int getnum(string temp){
	int ans=0;
	for(int i=0;i<temp.size();i++){
		ans=ans+(temp[i]-'0')*pow(10,temp.size()-i-1);
	}
	return ans;
}
string hash1[13]={"tret","jan","feb","mar","apr","may","jun","jly","aug","sep","oct","nov","dec"};
string hash2[12]={"tam","hel","maa","huh","tou","kes","hei","elo","syy","lok","mer","jou"};
int main()
{
	#ifndef ONLINE_JUDGE
	freopen("in.txt","r",stdin);
	#endif 
	int n;
	cin>>n;
	getchar();
	for(int i=0;i<n;i++){
		string temp;
		getline(cin,temp);
		if(temp.size()==4) cout<<0<<endl;
		else if(temp.size()>4){
			string temp1,temp2;
			temp1=temp.substr(0,3);
			temp2=temp.substr(4,3);
			int ans=0;
			for(int i=0;i<12;i++){
				if(hash2[i]==temp1){
					ans=ans+(i+1)*13;break;
				}
			}
			for(int i=1;i<13;i++){
				if(hash1[i]==temp2){
					ans=ans+i;break;
				}
			}
			cout<<ans<<endl;
		}else if(temp.size()<4){
			if(temp[0]<='9'&&temp[0]>='0'){
				int t=getnum(temp);
				if(t<=12){
					cout<<hash1[t]<<endl;
				}else if(t>12&&t<169){
					if(t%13!=0)
					cout<<hash2[t/13-1]<<' '<<hash1[t%13]<<endl;
					else cout<<hash2[t/13-1]<<endl;
				}
			}else if(temp[0]>='a'&&temp[0]<='z'){
				for(int i=0;i<13;i++){
					if(hash1[i]==temp){
						cout<<i<<endl;break;
					}
				}
				for(int i=0;i<12;i++){
					if(hash2[i]==temp){
						cout<<(i+1)*13<<endl;break; 
					}
				}
			}
		}
	}
	return 0;
}
 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值