UVa 893 - Y3K Problem
来源:互联网 发布:农村淘宝亏了好几万 编辑:程序博客网 时间:2024/04/28 04:10
題目:給你當前的日期,問再過k天后的日期。
分析:數論,曆法,閏年判斷。四年一閏,百年不閏,四百年閏。
計算當前日期距離0年1月1日有多少天+k天后從新計算日期即可。
說明:╮(╯▽╰)╭。
#include <cstdlib>#include <cstdio>int month[13] = {0,31,28,31,30,31,30,31,31,30,31,30,31};int baseday(int D, int M, int Y){int sum = D;for (int i = 0; i < Y; ++ i)if (i%4 == 0 && i%100 != 0 || i%400 == 0)sum += 366;else sum += 365;for (int i = 0; i < M; ++ i)sum += month[i];if (Y%4 == 0 && Y%100 != 0 || Y%400 == 0)if (M > 2)sum ++;return sum;}int main(){int days, D, M, Y;while (~scanf("%d%d%d%d",&days,&D,&M,&Y) && Y) {days += baseday(D, M, Y);for (Y = 0; ; ++ Y) {if (Y%4 == 0 && Y%100 != 0 || Y%400 == 0) {if (days <= 366)break;else days -= 366;}else if (days <= 365)break;else days -= 365;}for (M = 1; M <= 12; ++ M)if (M == 2) {if (Y%4 == 0 && Y%100 != 0 || Y%400 == 0) {if (days > 29) days -= 29;else break;}else if (days > 28)days -= 28;else break;}else if (days > month[M])days -= month[M];else break;printf("%d %d %d\n",days,M,Y);}return 0;}
0 0
- UVa 893 - Y3K Problem
- UVa 893 Y3K Problem (用GregorianCalendar类秒杀)
- UVa893 - Y3K Problem(用到java中的GregorianCalendar)
- UVa Problem 105 - Skyline Problem
- UVa Problem Category
- UVa Problem 12016 - Herbicide
- UVa Problem 104 - Arbitrage
- UVA 10104 - Euclid Problem
- uva 10104 - Euclid Problem
- UVA 105 Skyline Problem
- UVA The Blocks Problem
- uva 11898 - Killer Problem
- UVA Problem D: Hartals
- UVA - 11898 Killer Problem
- UVa 1531 - Problem Bee
- UVA Shoemaker's Problem
- UVa 10104 - Euclid Problem
- UVa 895 - Word Problem
- 【小知识点总结】android判断横竖屏
- Cocos2d-x中自定义XML的读取和写入
- 剑指offer—按之字形顺序打印二叉树
- Java-Selenium启动环境配置
- 卡榫函数实现API
- UVa 893 - Y3K Problem
- 南阳oj A+BproblemII Java 解决 题目103
- break 和continue以及return的区别
- 剑指offer—把二叉树打印成多行
- Leetcode87: Find Minimum in Rotated Sorted Array
- c#遍历checkBox控件,并用MessageBox显示出来
- [LeetCode-234] Palindrome Linked List(回文链表、链表中间节点查找)
- XML的自定义多极Map序列化和反序列化
- LA 3667 Ruler 两种不同形式的搜索来解决