PAT A 1100 AC代码

该程序读取输入的数字或英文日期,根据条件将其转换为特定格式的输出。当输入为数字时,判断是否为13的倍数,并进行相应月份的输出;若输入为英文,程序能解析完整的日期或单独的月份并输出对应的数字。程序涵盖了从0到12的月份以及大于13的非13倍数的情况。

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

细心点写,应分为 0     13的倍数    1到12     >13非13倍数 来考虑情况 否则很容易漏

#include<iostream>
using namespace std;
string word[2][13]=
{
	{"tret","jan","feb","mar","apr","may","jun","jly","aug","sep","oct","nov","dec"},
	{"tret","tam","hel","maa","huh","tou","kes","hei","elo","syy","lok","mer","jou"}
};
int main(){
	int N;
	cin>>N;
	getchar(); 
	for(int i=0;i<N;i++){
		string x;
		getline(cin,x);
		if('0'<=x[0]&&x[0]<='9'){
			int n=stoi(x);
			if(n%13==0){
				cout<<word[1][n/13];
			}else if(n>13){
				cout<<word[1][n/13]<<" "<<word[0][n%13];
			}else{
				cout<<word[0][n];
			}
		}else{
			if(x=="tret"){
				printf("0");
			}else if(x.length()==3){
				for(int j=1;j<13;j++){
					if(x==word[0][j]){
						cout<<j;
						break;
					}
					if(x==word[1][j]){
						cout<<j*13;
						break;
					}
				}
			}else{
				int ans=0;
				for(int j=1;j<13;j++){
					if(x.substr(0,3)==word[1][j]){
						ans+=j*13;
					}
					if(x.substr(4,6)==word[0][j]){
						ans+=j;
					}
				}
				cout<<ans;
			}
		}
		cout<<endl;
	}
	return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值