Programming contests

20 Programming Exercise for Beginners

January 1, 2019, 12:00 AM – December 31, 2019, 12:00 AM

Monthly Calendar

Create a program that draws a monthly calendar in the form of a table.

Input Specification

The input consists of two lines, each terminated by a newline character. The first line contains the number of days (an integer between 28 and 31). The second line contains one of the following words: Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, or Sunday, describing the first day of the month.

Sample Input

  1. 30
  2. Thursday
download as text file

Output Specification

The output is a table containing the day numbers within the month. Each row of the table represents a week, so they have 7 cells. The cells are separated by a single tab character. Each cell is two characters wide containing the right-aligned number of the day or two dots when the cell belongs to another month.

Output for Sample Input

  1. .. .. ..  1  2  3  4
  2.  5  6  7  8  9 10 11
  3. 12 13 14 15 16 17 18
  4. 19 20 21 22 23 24 25
  5. 26 27 28 29 30 .. ..
download as text file

Hints and Guide

The two lines of the input contain information of different types. The first line consists of a number, the second contains a word from a given set. Because we want to read two input lines, we suggest to use the fgets function from the standard input-output library. The first line as a string can easily be converted to integer with the help of the atoi function, and the content of the second line can be compared to the names of the days with the help of the strcmp function. Note that the strings are terminated with a newline character.

Each output line must contain exactly 7 cells. We have to construct lines until all the days are printed. If the month does not start with Monday, then the first few cells must be skipped.

One possible solution is available in: main.c.

Acknowledgement This work was supported by the construction EFOP-3.4.3-16-2016-00021. The project was supported by the European Union, co-financed by the European Social Fund.
University of Debrecen; Faculty of Informatics; v. 09/30/2024