F.A.Q
Hand In Hand
Online Acmers
Problem Archive
Realtime Judge Status
Authors Ranklist
 
     C/C++/Java Exams     
ACM Steps
Go to Job
Contest LiveCast
ICPC@China
Best Coder beta
VIP | STD Contests
    DIY | Web-DIY beta
Author ID 
Password 
 Register new ID

Anniversaries

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 312    Accepted Submission(s): 8


Problem Description
As far as our perceptions are concerned, a year runs from the midnight beginning the first of January to the midnight ending the 31st of December. Thus we can say that a year consists of:
12 months (of differing lengths)
52 (and a bit) weeks
365 days
8,760 hours
525,600 minutes
31,536,000 seconds.
Most of these numbers need to be adjusted in leap years.

A k'th anniversary of a date is usually defined as the same date (month and day) k years later, thus the 10th anniversary of 17th May 1983 is 17th May 1993. However we can also define other types of `versaries' - the 1 week-versary of 28th February 1984 is 6th March 1984.

If we define a convention of naming dates (and times if necessary) by specifying successively smaller periods separated by colons (that is as yyyy:mm:dd:hh:mm:ss) we can label the units using the same convention, that is y for years, d for days, w for weeks, h for hours, m for minutes and s for seconds (we cannot use months, they are too variable). We can then summarise the above examples as:
1983:5:17 + 10y -> 1993:5:17
1984:2:28 + 1w -> 1984:3:6
Note that the specification of an event has to be as least as precise (that is employ units at least as small) as the specification of the desired versary.

Write a program that will read in details of events and desired versaries and calculate the required date (and time if necessary). Bear in mind that a year is a leap year if it is divisible by 4 unless it is divisible by 100 as well, in which case it is only a leap year if it is divisible by 400; thus 1984 and 2000 are leap years, but 1900 is not.

 

Input
Input will consist of a series of lines, each line a specification of an event and a desired versary. The input will follow the format shown below, except that where one space is shown there may be more than one space. The event will be specified at least to the same precision as the desired versary. All events will start in this century, and no versary will be more than 100 years (or equivalent). Note that midnight starts a day rather than terminates it and thus is written as 0:0:0 and not as 24:0:0. The file will be terminated by a line consisting of a single 0.

 

Output
Output will consist of a series of lines, one for each line of the input. Each line will consist of the specification of the desired versary, to the same precision as given in the input, in the format shown below.

 

Sample Input
1983:5:17 10 y 1984:2:28 1 w 1993:7:25:13:23 5 h 0
 

Sample Output
1983:5:17 + 10y -> 1993:5:17 1984:2:28 + 1w -> 1984:3:6 1993:7:25:13:23 + 5h -> 1993:7:25:18:23
 

Source
 

Statistic | Submit | Discuss | Note
Hangzhou Dianzi University Online Judge 3.0
Copyright © 2005-2024 HDU ACM Team. All Rights Reserved.
Designer & Developer : Wang Rongtao LinLe GaoJie GanLu
Total 0.000000(s) query 1, Server time : 2024-05-12 10:24:14, Gzip enabled