AcWing 1341. 十三号星期五---日期模拟
原题链接
简单
作者:
会飞的泡泡
,
2021-03-17 22:07:01
,
所有人可见
,
阅读 456
日期模拟
#include <iostream>
#include <algorithm>
using namespace std;
int months[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};
int weekday[7];
int getyear(int year,int m){
if(m!=2)return months[m];
if(year%4==0 && year%100 || year%400==0)return 29;
else return 28;
}
int main(){
int n;
cin>>n;
int week=0;
int year=1900,month=1,day=1;
while(year<1900+n){
if(day==13)weekday[week]++;
week=(week+1)%7;
day++;
if(day>getyear(year,month)){
day=1;
month++;
}
if(month>12){
month=1;
year++;
}
}
for(int i=5,j=0;j<7; j++,i=(i+1)%7){
cout<<weekday[i]<<" ";
}
return 0;
}
AcWing【AC之星】教育优惠计划!https://www.acwing.com/user/security/school_verify/ac_stars/ 我的邀请码是:GUDFH