Programming contests

50 Programming Exercise for Beginners

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

Temperature Fluctuation

Write a program that reads lines in the following format until end-of-file from the text file given as the first command line argument:

settlement_name: temperature,temperature[,temperature]...

settlement_name is a string of up to 30 characters, the temperature data are signed integers, and the total length of the line does not exceed 1000 characters. Each line contains the temperature data for a given settlement in a certain time interval. We do not know the exact number of measurements, but we know that at least two but no more than five hundred measurements are made during the time interval. For each settlement, the program should write to the standard output the temperature fluctuation during the time interval, i.e., the difference between the largest and the smallest measured temperature. The format of each line in the output should be as follows:

settlement_name: temperature_fluctuation

Sample Input

  1. Debrecen: 10,8,8,8,9,9,11,14,14,15,17,16,16,14,15,17,19,17,18,14
  2. Hatvan: 18,3
  3. Funchal: 18,18,18,18,18,18,18,18,18
  4. Liverpool: 14,15,16,17,16,17,13,10,12,4,2,3,5,12,17
  5. Murmanszk: 1,0,-1,-3,-3,-2,0,1,2
download as text file

Output for Sample Input

  1. Debrecen: 11
  2. Hatvan: 15
  3. Funchal: 0
  4. Liverpool: 15
  5. Murmanszk: 5
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