ZeroJudge E807: Rainfall Statistics

During the summer vacation, heavy rainfall caused severe flooding in Gaoxiong City due to typhoons and southwest monsoons, leaving Mayor Dong Dong frustrated. Therefore, Dongfeng, who lives in Kaohsiung, wants to organize and summarize the rainfall situation for one week (Monday to Sunday) to help share the mayor's burden. Please output the rainfall information Dongfen wants to know based on the given data. The rainfall is recorded for four periods each day: morning, afternoon, night, and early morning. The total rainfall for each day is the sum of the rainfall in these four periods.

Sample Inputs/Outputs

Sample Input(s)Sample Output(s)
The input consists of seven lines, each representing the rainfall information from Monday to Sunday. Each line contains 4 floating-point numbers: M, A, N, E (with one decimal place, 0 <= M, A, N, E <= 50), representing the rainfall amount in millimeters for each of the four periods of the day.For each set of data, output a positive integer D and a period of the day separated by a new line. The first line should contain the positive integer D (1 <= D <= 7), representing the day with the highest rainfall within the week (1 to 7 corresponding to Monday to Sunday). The second line should output the day with the highest rainfall within the week. There will be no duplicate occurrences of the maximum daily rainfall total and the maximum period rainfall total in the test data.
2.3 18.4 0.3 0.0
1.5 10.8 22.4 11.1
0.5 15.8 25.0 16.4
0.0 4.6 0.0 0.4
9.7 5.9 3.2 1.7
1.8 2.1 0.0 7.2
0.7 10.2 2.2 5.8
3
afternoon
10.7 2.6 7.8 20.0
2.7 3.5 40.1 35.4
0.0 13.2 20.6 12.1
19.2 2.4 3.8 4.0
15.5 14.3 16.9 5.5
4.5 5.7 7.8 0.0
13.2 3.4 5.1 9.6
2
night
ZeroJudge E807 範例測資

Thought Process

To determine the maximum total daily rainfall, store the day with the maximum value and output it.

Declare a Map, where the keys are "morning", "afternoon", "night", and "early morning". Add the rainfall amounts for different time periods to these keys. Then, iterate through the map using a for loop (for (auto it : Map)). Initialize a pair named ans, and set ans.second to -1. If it.second > ans.second, update ans = it. Finally, output ans.first.

Sample Code-ZeroJudge E807: Rainfall Statistics

#include <iostream>
#include <map>
using namespace std;

int main() {
    cin.sync_with_stdio(0);
    cin.tie(0);
    float max = -1;
    int max_day;
    map<string, float>MAP;
    for (int i = 1; i<=7; i++)
    {
        float a, b, c, d;
        cin >> a >> b >> c >> d;
        float sum = a + b + c + d;
        if (sum > max)
        {
            max = sum;
            max_day = i;
        }
        MAP["morning"] += a;
        MAP["afternoon"] += b;
        MAP["night"] += c;
        MAP["early morning"] += d;
    }
    cout << max_day << "\n";
    pair<string, float>ans;
    ans.second = -1;
    for (auto it:MAP)
    {
        if (it.second > ans.second) ans = it;
    }
    cout << ans.first << "\n";
}

//ZeroJudge E807
//Dr. SeanXD

Comments