Sicily 1791. Philia's Problem
来源:互联网 发布:淘宝哪家螺蛳粉好吃 编辑:程序博客网 时间:2024/04/30 13:50
关键在于判断给出的日期是星期几,要自己写一个函数来判断的话就比较麻烦,可以直接调用zeller函数,相当省事。另外注意年月日的进位就没事了。
Run Time: 0.01sec
Run Memory: 304KB
Code length: 1194Bytes
SubmitTime: 2011-12-11 13:35:04
// Problem#: 1791// Submission#: 1064449// The source code is licensed under Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License// URI: http://creativecommons.org/licenses/by-nc-sa/3.0/// All Copyright reserved by Informatic Lab of Sun Yat-sen University#include <cstdio>using namespace std;int days[ 13 ] = { 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };int zeller( int year, int month, int day ) { if ( month < 3 ) { year = year - 1; month = month + 12; } int q = year / 100; int m = year % 100; int ans = ( q / 4 - 2 * q + m + m / 4 + ( 26 * ( month + 1 ) ) / 10 + day - 1 ) % 7; return ( ans > 0 ? ans: ans + 7 );}int main(){ int N; int year, month, day; int diff; scanf( "%d", &N ); while ( N-- ) { scanf( "%d%d%d", &month, &day, &year ); diff = 7 - zeller( year, month, day ); if ( diff == 0 ) diff = 7; if ( month == 2 ) days[ 2 ] = ( year % 400 == 0 || ( year % 4 == 0 && year % 100 != 0 ) ? 29: 28 ); day += diff; if ( day > days[ month ] ) { day -= days[ month ]; if ( month <= 11 ) month++; else { month = 1; year++; } } printf( month >= 10 ? "%d ": "0%d ", month ); printf( day >= 10 ? "%d ": "0%d ", day ); printf( "%d\n", year ); } return 0;}
- Sicily 1791. Philia's Problem
- Sicily 1791. Philia's Problem
- Sicily 1792. Hengheng's Problem
- Sicily 1085.Longge's problem
- sicily 1085. Longge's problem
- Sicily 1085. Longge's problem
- Sicily 1902. Counting Problem
- Sicily 1902. Counting Problem
- <Sicily>Threecolor problem
- sicily 1441 pie[S]
- Sicily 1157. The hardest problem
- sicily--1157. The hardest problem
- sicily 1157.The hardest problem
- Sicily 1157. The hardest problem
- Sicily 1157 the hardest problem
- [sicily]1157. The hardest problem
- Problem S
- Problem-S
- diff和patch给源码做补丁
- 黑马程序员——多线程原来是这么简单
- 风、寒、暑、湿、燥、火
- mmap()介绍
- 新年开始,小计一页
- Sicily 1791. Philia's Problem
- 宏中"#"和"##"的用法
- 站在大二时的遗憾,和那些能够或不能够挽回的青春
- 介紹好用工具:Process Explorer
- Sicily 1793. Numbers
- 为什么我要把公司做成扁平型
- sigaction实例
- Sicily 1794. Missiles
- 架构师之路