# 12611 - The Same Calendar ## 題解: 有相同的日曆的條件是1月1日星期幾是相同的且一年的天數相同。 每加一年的話,1月1日的星期幾就要加一, 如果遇到閏年就是加二,直到符合上述條件,就是答案。 **Reference:http://codeforces.com/blog/entry/45405** ## Code: ```c=1 #include <stdio.h> #include <stdbool.h> bool isLeap(int y){ return y % 400 == 0 || (y % 4 == 0 && y % 100 != 0); } int main(){ int t, y; scanf("%d", &t); while(t--){ scanf("%d", &y); bool leap = isLeap(y); // days int d = 0; // week while(true){ y++, d++; if(isLeap(y)) d++; d %= 7; if(d == 0 && isLeap(y) == leap) break; } printf("%d\n", y); } return 0; } ``` ###### tags: `NTHUOJ`
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up