CodeForces
来源:互联网 发布:ps淘宝详情页参数 编辑:程序博客网 时间:2024/06/05 06:07
题目连接:http://codeforces.com/problemset/problem/678/B
题目描述
Description
The girl Taylor has a beautiful calendar for the year y. In the calendar all days are given with their days of week: Monday, Tuesday, Wednesday, Thursday, Friday, Saturday and Sunday.
The calendar is so beautiful that she wants to know what is the next year after y when the calendar will be exactly the same. Help Taylor to find that year.
Note that leap years has 366 days. The year is leap if it is divisible by 400 or it is divisible by 4, but not by 100 (https://en.wikipedia.org/wiki/Leap_year).
Input
The only line contains integer y (1000 ≤ y < 100’000) — the year of the calendar.
Output
Print the only integer y’ — the next year after y when the calendar will be the same. Note that you should find the first year after y with the same calendar.
Sample Input
2016
Sample Output
2044
Sample Input
2000
Sample Output
2048
Sample Input
50501
Sample Output
50507
解题思路
计算两个相同的一年,一样的话,如果1月1号是周1,那么输的那一年也是周1,那么中间的天数得是7 的倍数,365 % 7 = 1, 366 % 7 = 2,如果是平年就加 1 ,闰年加 2 ,直到是7的倍数停止 ,注意,如果开始是平年的话,结果也是平年
AC代码
#include<iostream>using namespace std;int check(int n) { if((n%400 == 0) || (n%4 == 0 && n%100 != 0)) return 1; return 0;}int main () { int y; while(~scanf("%d", &y)) { int sum = 0; int i; for(i = y+1; ; i++) { if(check(i)) { sum += 2; } else { sum += 1; } if(sum%7 == 0 && (check(y) == check(i))) break; } printf("%d\n", i); } return 0; }
- codeforces~~~
- Codeforces
- codeforces
- Codeforces
- codeforces
- codeforces
- Codeforces
- Codeforces
- CodeForces
- CodeForces
- CodeForces
- CodeForces
- CodeForces
- Codeforces
- Codeforces
- Codeforces
- Codeforces
- Codeforces
- Android全局异常处理(捕获异常,不弹出程序崩溃)
- MYSQL问题解决方案:Access denied for user 'root'@'localhost' (using password:YES)
- Android 自定义View (二) 进阶
- SDK接入遇到的问题
- 06 ZStack的task工作流程分析
- CodeForces
- SQL查询 从第N条记录开始显示M行
- 网络编程—链路层报文、网络层IP报文、传输层TCP报文
- D3.js 数据可视化学习笔记——Hello D3!
- R分类算法-神经网络算法
- 布全Micromine.GBIS.v7.8.0.60矿业专业软件
- Android 自定义View (三) 圆环交替 等待效果
- Android json解析 Gson工具类
- JDK版本新特性介绍&JDK1.6