Timus 1201. Which day is it?

Source: Internet
Author: User
Tags integer numbers
Document directory
  • Input
  • Output
  • Samples
Timus 1201. Which day is it? The calendar of the specified date must be output.

1201. Which day is it? Time Limit: 1.0 second
Memory limit: 16 mbsometimes it is of great importance to know which day of the week a given date will be. and we start searching for the nearest calendar. being lucky we may find one. and find out that this one does not contain the date you need. what a pity! Thus you are asked to create a calendar that will be able to process any given date in the years range from 1600 till 2400. given a date, your program shocould print (see the examples below) a correct calendar for the month containing the date. do not forget about the leap years. A year is considered to be leap if it is multiple of 4 blocks t it is multiple of 100 blocks t it is multiple of 400. for example 1996 is a leap year, 1900 is not a leap year (it is a multiple of 4 and multiple of 100) and 2000 is a leap year (it is a multiple of 4, multiple of 100 and multiple of 400 as well ). inputthe first line of input contains a date, I. e. three integer numbers: Day (1-31), month (1-12) and year (1600-2400) separated by spaces. outputthe output shoshould contain exactly 7 lines with the correct calendar for the month containing the given date. format of a calendar is given by the examples below (for a reading convenience spaces in output example are replaced with dots, real output shoshould contain spaces instead ). and do not forget to highlight the given date by square brackets. samples
Input Output
16 3 2002
mon........4...11...18...25tue........5...12...19...26wed........6...13...20...27thu........7...14...21...28fri...1....8...15...22...29sat...2....9..[16]..23...30sun...3...10...17...24...31         
1 3 2002
mon........4...11...18...25tue........5...12...19...26wed........6...13...20...27thu........7...14...21...28fri.[.1]...8...15...22...29sat...2....9...16...23...30sun...3...10...17...24...31         

Problem Author:Alexander klepinin
Problem Source:USU internal contest, March 2002

The answer is as follows:

1 using system;
2
3 namespace skyiv. Ben. timus
4 {
5 // http://acm.timus.ru/problem.aspx? Space = 1 & num = 1201
6 Sealed class t1201
7 {
8 Static void main ()
9 {
10 var Ss = console. Readline (). Split ();
11 var dt = new datetime (Int. parse (ss [2]), Int. parse (ss [1]), Int. parse (ss [0]);
12 var D0 = DT. adddays (1-Dt. Day );
13 var K =-(INT) d0.dayofweek + 6) % 7 );
14 string [] weeks = {"mon", "Tue", "wed", "Thu", "fri", "sat", "Sun "};
15 For (VAR I = 0; I <weeks. length; I ++)
16 {
17 console. Write (weeks [I]);
18 For (VAR d = d0.adddays (K + I); D <d0.addmonths (1); D = D. adddays (7 ))
19 console. Write (d <D0 )? "": (D! = DT )?
20 (D> = d0.adddays (K + 7) & D! = DT. adddays (7 ))? "": "") + "{0, 4 }"):
21 (D> = d0.adddays (K + 7 ))? "": "") + "[{0, 2}]"), D. Day );
22 console. writeline ();
23}
24}
25}
26}

This question is quite simple, that is, pay attention to the output format, especially the format of the input date on that day.

The input date range of this question is from 1600 to 2400. I want to avoid the following problem: the next day of October 4, 1582 is October 15, 1582.

This program is from the csdn forum.Zhige (min_jie)A friend's post: "It will time out, why ?", Modified and reconstructed the program on the 23rd floor in this post.

This program can be further simplified. The statements from lines 19th to 21 can be replaced with the following line:

Console.Write((d < d0) ? "     " : ((d != dt) ? "{0,4} " : " [{0,2}]"), d.Day);

Note that this is no longer a strict reconstruction. In fact, the output of the program has changed, add a space after the last column of each row (except when the last character of the row is the right brace ). Although the output of this program is different from the output in the example of the question, it is simpler and more logical, because the number of characters in each line is the same, and the number of characters in each column is the same (both five characters ). Based on the example of the question, if the right brace "]" is the last character of a line, the number of characters in the line will be one more than that in other lines. Most importantly, the modified program can pass the timus system test and the result is accept.

Returned directory

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.