Programming contests

50 Programming Exercise for Beginners

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

Following the Passing Time

Write a function that takes a string as a parameter containing a time of the week in the following format:

dayname_abbreviation hour.min

The dayname_abbreviation is one of „H”, „K”, „Sze”, „Cs”, „P”, „Szo”, „V”. (These days appear in the traditional Hungarian order of weekdays, but with their Hungarian abbreviations: H – „Monday”, K – „Tuesday”, Sze – „Wednesday”, Cs – „Thursday”, P – „Friday”, Szo – „Saturday”, V – „Sunday”.) The time is in 24-hour format, i.e., hour is between 0–23, and min is between 0–59. The function should determine and return the number of minutes elapsed between the beginning of the week and the specified time of the week, assuming that the week starts on Monday at 0.00 and that there is no change in daylight saving time set for the week.

The specification of the function

int minutes( char * );

Note

Place the function in a file named minutes.c and submit this file as a solution to the evaluation system. You can test your solution using the following files. The evaluation system does not necessarily perform the evaluation using these files.

main.c

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. int main()
  4. {
  5.   char line[ 1000 ];
  6.   int minutes( char * );
  7.   while ( gets( line ) != NULL )
  8.     printf( "%d\n", minutes( line ) );
  9.   return EXIT_SUCCESS;
  10. }
download as text file

Makefile

  1. CC = gcc
  2. OBJS = main.o minutes.o
  3. TARGETS = main 
  4. all: $(TARGETS)
  5. main: main.o minutes.o
  6. $(CC) main.o minutes.o -o main
  7. main.o: main.c
  8. $(CC) -c main.c
  9. minutes.o: minutes.c
  10. $(CC) -c minutes.c
  11. clean:
  12. rm -rf $(OBJS) *~ $(TARGETS)
download as text file

Sample Input

  1. H 0.00
  2. H 23.59
  3. Sze 12.00
  4. V 23.59
download as text file

Output for Sample Input

  1. 0
  2. 1439
  3. 3600
  4. 10079
download as text file

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. 03/01/2019