纯模拟,有注释,0pts,求助!!!orz
查看原帖
纯模拟,有注释,0pts,求助!!!orz
817450
Calarence4楼主2023/10/19 13:13
#include<bits/stdc++.h>
using namespace std;


int Q;
int mouths[12+1]={0,31,28,31,30,31,30,31,31,30,31,30,31};


string change(long long);
bool isLeapYear(int,bool);


int main(){
	scanf("%d",&Q);
	for(int i=1;i<=Q;i++){
		long long r;
		scanf("%lld",&r);
		printf("%s\n",change(r).c_str());//printf不可输出字符串,参数只能提供char *,参数应为 字符串变量名.c_str()
	}
	return 0;
}


string change(long long rday){//第零天:1 1 4713 BC
	int Day = 1;
	int Mouth = 1;
	long long Year = -4713;//负数表示BC,正数表示AC
	bool isLY=false;
	bool LY_4=true;//true表示只要是4的整数倍就是闰年
	string answer="";
	for(int i=1;i<=rday;i++){
		if(Day==5&&Mouth==10&&Year==1582){//到达5 10 1582
			Day=15;//此天为4 10 1582的下一天,则应该为15 10 1582
			LY_4=false;
			continue;//不再进行进位,直接continue
		}
		if(Mouth==2){
			isLY=isLeapYear(Year,LY_4);//true为闰年
			mouths[2]=isLY?29:28;
		}
		if(++Day>mouths[Mouth]){
			Day=1;
			Mouth++;
		}
		if(Mouth>13){
			Mouth=1;
			Year++;
			if(Year==0){//不存在公元0年
				Year=1;
			}
		}
		/*{//调试
			if(Year<0){
				answer=to_string(Day)+" "+to_string(Mouth)+" "+to_string(abs(Year))+" BC";
			}
			else{
				answer=to_string(Day)+" "+to_string(Mouth)+" "+to_string(abs(Year));
			}
			printf("%s\n",answer.c_str());
		}*/
	}
	
	
	
	if(Year<0){
		answer=to_string(Day)+" "+to_string(Mouth)+" "+to_string(abs(Year))+" BC";
	}
	else{
		answer=to_string(Day)+" "+to_string(Mouth)+" "+to_string(abs(Year));
	}
	return answer;
}


bool isLeapYear(int Year,bool LY_4){
	if(LY_4){
		if(Year<0){
			Year=abs(Year)-1;
		}
		if(Year%4==0){
			return true;
		}
		else{
			return false;
		}
	}
	if(!LY_4){
		if(Year%400==0){
			return true;
		}
		else if(Year%100!=0&&Year%4==0){
			return true;
		}
		else{
			return false;
		}
	}
}
2023/10/19 13:13
加载中...