3 solutions
-
0
#include<iostream> using namespace std; int days[] = {0,31,28,31,30,31,30,31,31,30,31,30,31}; int is_leap(int y){ //判断闰年 return y % 400 == 0 || y % 4 == 0 && y % 100 != 0; } int daysOfMonth(int y, int m){ if( m == 2) return is_leap(y) + 28; return days[m]; } int main(){ int y = 2000, m = 1, d = 1, w = 6; // 年,月,日,周几 int ans = 0; while(y != 2020 || m != 10 || d != 2){ if(d == 1 || w == 1) ans += 2; else ans++; d++; if(d > daysOfMonth(y, m)) d = 1, m++; if(m > 12) m = 1, y++; w++; if(w == 8) w = 1; } cout << ans << endl; return 0; }
-
0
#include<bits/stdc++.h> using namespace std; int week=6,sum; int main(){ for(register int year=2000;year<=2020;year++){ int a[13]={0,31,28,31,30,31,30,31,31,30,31,30,31}; if((year%4==0&&year%100!=0)||year%400==0)a[2]=29;//闰年特判 for(register int month=1;month<=12;month++) for(register int day=1;day<=a[month];day++){ if(day==1||week==1)sum+=2;//月初或者周一 else sum++; week=(week+1)%7;//星期数增加 if(year==2020 && month==10 && day==1){ cout<<sum; return 0; } } } }
-
0
闰年是能被400整除或者能整除4但不能整除100的年,闰年2月份是29天,非闰年是28天
#include <bits/stdc++.h> using namespace std; #define ll long long #define endl "\n" int yue[13]={0,31,28,31,30,31,30,31,31,30,31,30,31}; int main(){ ll ans=0; int zhou=5; for(int i=2000;i<=2020;i++){ if(i%400==0||(i%4==0&&i%100!=0)){ yue[2]=29; } else yue[2]=28; for(int j=1;j<=12;j++){ for(int k=1;k<=yue[j];k++){ zhou++; zhou%=8; if(zhou==0) zhou=1; if(zhou==1||k==1) ans+=2; else ans++; if(i==2020&&j==10&&k==1){ cout<<ans; return 0; } } } } return 0; }
- 1
Information
- ID
- 6481
- Time
- 1000ms
- Memory
- 256MiB
- Difficulty
- 7
- Tags
- # Submissions
- 59
- Accepted
- 25
- Uploaded By