10分求调
查看原帖
10分求调
798795
___Segment___楼主2024/8/27 16:55

rt。

#include<bits/stdc++.h>
using namespace std;
long long m_s=60,h_s=m_s*60,d_s=h_s*24,mo_s[13]={0,d_s*31,d_s*28,d_s*31,d_s*30,d_s*31,d_s*30,d_s*31,d_s*31,d_s*30,d_s*31,d_s*30,d_s*31},py_s=d_s*365,ry_s=d_s*366; //记录各个时间之间单位的进率 

bool isrun(int y) {
	return y%4==0&&y%100!=0||y%400==0||y%3200==0;
}

int main() {
	int T;
	scanf("%d",&T);
	while(T--) { //多组数据 
		int year,month,day,hour,min,sec,x;
		scanf("%d-%d-%d %d:%d:%d %d",&year,&month,&day,&hour,&min,&sec,&x);
		
		if(isrun(year)) mo_s[2]=d_s*29; //闰年二月29天 
		
		long long sx=x*60; //记录以秒为单位的x 
		long long _time=day*d_s+hour*h_s+min*m_s+sec; //记录当前时间从纪元时间开始过去的秒数
		
		for(int i=year-1;i>=1970;i--) { //将年转换为秒 
			if(isrun(i)) _time+=ry_s;
			else _time+=py_s;
		}
		for(int i=month-1;i>=1;i--) _time+=mo_s[i]; //将月份转换为秒 
		
		while(_time%sx!=0) _time--; //查找闹钟响起的时间
		
		year=1970;
		while(true) { //将秒转换为年 
			if(isrun(year)) {
				if(_time<ry_s) break;
				_time-=ry_s;
			}
			else {
				if(_time<py_s) break;
				_time-=py_s;
			}
			year++;
		}
		
		month=1;
		while(_time>=mo_s[month]) { //将秒转换为月份 
			_time-=mo_s[month];
			month++;
		}
		
		day=_time/d_s; //将秒转换为天
		_time%=d_s;
		
		hour=_time/h_s; //将秒转换为时
		_time%=h_s;
		
		min=_time/m_s; //将秒转换为分 
		_time%=m_s;
		
		sec=_time;
		
		printf("%d-%d-%d %d:%d:%d\n",year,month,day,hour,min,sec);
	}
	return 0;
}
2024/8/27 16:55
加载中...