coreBugZJ

此 blog 已弃。

The Date, FZU 2011年3月月赛之 E, FZU 2014

Problem 2014 The Date

Time Limit: 1000 mSec    Memory Limit : 32768 KB

Problem Description

abcdxyzk believes that 2012.12.21 is the doomsday after he watched the movie “2012”. He counts how many days later the doomsday will come! However he doesn’t keep the date in mind!

You are given one integer N, indicating N days later, the doomsday will come, and abcdxyzk wants to know the date now!

Input

There are several test cases.

For each case, only one integer N in a single line , indicating N days later, the doomsday will come. (1<=n<= 1000000)

Output

For each test case, output the date now in format “yyyy-mm-dd”, where “yyyy” is the year, “mm” is the month and “dd” is the day.

Sample Input

1085
1

Sample Output

2010-01-01
2012-12-20

Source

FOJ有奖月赛-2011年03月



简单模拟


 1 #include <stdio.h>
 2 
 3 #define  L  1000009
 4 
 5 int year[ L ], month[ L ], day[ L ];
 6 
 7 int isint y ) {
 8         return (y%400==0|| ((y%100!=0)&&(y%4==0));
 9 }
10 
11 void init() {
12         int totD[] = { 0312831303130313130313031 };
13         int i;
14         year[ 0 ] = 2012;
15         month[ 0 ] = 12;
16         day[ 0 ] = 21;
17         for ( i = 1; i < L; ++i ) {
18                 year[ i ] = year[ i - 1 ];
19                 month[ i ] = month[ i - 1 ];
20                 day[ i ] = day[ i - 1 ];
21                 if ( --day[ i ] == 0  ) {
22                         if ( --month[ i ] == 0 ) {
23                                 --year[ i ];
24                                 month[ i ] = 12;
25                         }
26                         day[ i ] = totD[ month[ i ] ];
27                         if ( (is(year[i])) && (month[i]==2) ) {
28                                 ++day[ i ];
29                         }
30                 }
31         }
32 }
33 
34 int main() {
35         int n;
36         init();
37         while ( scanf("%d"&n) == 1 ) {
38                 printf( "%4d-%02d-%02d\n", year[n], month[n], day[n] );
39         }
40         return 0;
41 }
42 


posted on 2011-03-20 20:07 coreBugZJ 阅读(1366) 评论(0)  编辑 收藏 引用 所属分类: ACM


只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   博问   Chat2DB   管理