AcWing 3218. 日期计算
原题链接
简单
作者:
CqAq
,
2024-04-08 15:25:59
,
所有人可见
,
阅读 2
算法1
C++ 代码
#include <bits/stdc++.h>
using namespace std;
int y, d;
bool tag;
bool isrun(int year){
return (year % 4 == 0 && year % 100 != 0) || year % 400 == 0;
}
int day[] = {31,28,31,30,31,30,31,31,30,31,30,31};
void solve(){
if(tag) day[1] = 29;
int i = 0;
while(d > day[i]) d -= day[i ++];
//-- i;
int j = 1;
cout << i + 1 << '\n' << d << '\n';
}
int main(){
ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
cin >> y >> d;
if(isrun(y)) tag = true;
else tag = false;
solve();
return 0;
}