当前位置: 代码迷 >> 综合 >> 欧拉计划19--Counting Sundays
  详细解决方案

欧拉计划19--Counting Sundays

热度:49   发布时间:2023-11-25 20:59:22.0

结果:171

#include<iostream>
using namespace std;int main()
{int a[13]= {0,31,28,31,30,31,30,31,31,30,31,30,31};int day=1,ans =0;for(int i=1900;i<=2000;i++){if((i%4==0&&i%100!=0)||(i%400==0)){a[2] = 29;}else{a[2]=28;}for(int j=1;j<=12;j++){day+=a[j];if(day%7==0&&i>1900){ans++;}}}cout<<ans<<endl;return 0;
}