COLLABRAINS-Editorials 5

PROBLEM CODE
VIEW2005

PROBLEM LINK:
https://www.codechef.com/QTCC2020/problems/VIEW2005

DIFFICULTY:
Easy

PREREQUISITES:
math

PROBLEM :
Given the actual high and low temperatures for the day and the normal high and low temperatures for that day, calculate the average difference from normal.

EXPLANATION:
The first line of the data set for this problem is an integer that represents the number of data sets that follow. Each data set is on a separate line and consists of today’s high, today’s low, normal high, and normal low – in that order.If the average difference is negative, do not output the negative sign (-). Output the amount of deviation from normal, followed by the words DEGREE(S) ABOVE NORMAL, or by the words DEGREE(S) BELOW NORMAL. Round to 1 decimal place. A trailing zero is required if the average is an integer. The output is to be formatted exactly like that for the sample output given below.Temperatures are in the range –15…100 degrees. The average temperature difference will not be zero.Determine the average of the difference of the high temperatures and the difference of the low temperatures.

SOLUTIONS:

Summary

#include<stdio.h>
int main ()
{
int dataset;
scanf ("%d", &dataset);

while ( dataset-- ) {
    int today_high;
    int today_low;
    int normal_high;
    int normal_low;

    scanf ("%d %d", &today_high, &today_low);
    scanf ("%d %d", &normal_high, &normal_low);

    double lead = today_high - normal_high;;

    if ( today_low > normal_low )
        lead += today_low - normal_low;

    else
        lead += normal_low - today_low;

    if ( lead > 0 )
        printf ("%.1lf DEGREE(S) ABOVE NORMAL\n", lead / 2);
    else
        printf ("%.1lf DEGREE(S) BELOW NORMAL\n", lead / 2 * -1);
}

return 0;

}

Feel free to Share your approach.Suggestions are welcomed as always had been. :slight_smile: