AcWing 3391. 今年的第几天?
原题链接
简单
作者:
ᔠዂϤ
,
2022-02-25 12:45:55
,
所有人可见
,
阅读 185
C++ 代码
#include <iostream>
using namespace std;
const int month[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
bool is_leap(int year) { return year % 400 == 0 || year % 4 == 0 && year % 100; }
int solve(int year, int mon, int date)
{
int res = mon > 2 && is_leap(year) ? 1 : 0;
for (int i = 1; i < mon; i++)
res += month[i];
return res + date;
}
int main()
{
int year, mon, date;
while (~scanf("%d%d%d", &year, &mon, &date))
printf("%d\n", solve(year, mon, date));
}