AcWing 3218. 日期计算
原题链接
简单
作者:
把这题Ac了
,
2024-11-19 17:11:56
,
所有人可见
,
阅读 2
#include <iostream>
using namespace std;
int year,day;
int months[13] = {
0,31,28,31,30,31,30,31,31,30,31,30,31
};
int is_leap(int year){
if(year % 400 == 0 || year % 4 == 0 && year % 100 != 0) return 1;
return 0;
}
int main(){
cin >> year >> day;
int i = 1;
for(;i <= 12;i++){
if(day > months[i]){
if(i == 2 && day > months[i] + is_leap(year)){
day -= months[i] + is_leap(year);
}else if(i != 2){
day -= months[i];
}else{
break;
}
}else{
break;
}
}
cout << i << endl;
cout << day << endl;
return 0;
}