AcWing 3218. 日期计算
原题链接
简单
作者:
acwing_陌路
,
2021-02-21 21:13:00
,
所有人可见
,
阅读 411
简单模拟即可
#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
using namespace std;
int day,month;
int days[13] = {0,31,28,31,30,31,30,31,31,30,31,30,31};
int leap(int year)
{
if(year % 4 == 0 && year % 100 != 0 || year % 400 == 0) return 1;
return 0;
}
int main()
{
int year,num;
cin >> year >> num;
days[2] += leap(year);
int cnt = 1;
while(num)
{
if(num <= days[cnt])
{
month = cnt;
day = num;
break;
}
else
{
num -= days[cnt];
cnt++;
}
}
cout << month << endl << day << endl;
return 0;
}