Jinjin has started junior high school. Her mother thinks Jinjin should study harder, so Jinjin not only goes to school but also attends various review classes her mother has signed her up for. Additionally, every week her mother sends her to learn recitation, dance, and piano. However, Jinjin will get upset if she has more than eight hours of classes in a day, and the longer she stays, the more upset she becomes. Assuming Jinjin does not get upset for other reasons, her upset mood does not persist until the next day. Can you help check Jinjin's schedule for next week to see if she will be upset? If so, on which day will she be the most upset?
Sample Inputs/Outputs
Sample Input(s) | Sample Output(s) |
---|---|
Each set of input consists of seven lines of data, representing Jinjin's schedule from Monday to Sunday. Each line includes two non-negative integers less than 10, separated by a space, indicating the time Jinjin spends at school and the time her mother arranges for her classes, respectively. | Each set of output consists of one line containing a single number. If Jinjin will not be unhappy, output 0. If she is unhappy, output the day of the week when she will be the most unhappy (using 1, 2, 3, 4, 5, 6, 7 to represent Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, and Sunday, respectively). If there are two or more days with equal levels of unhappiness, output the day that occurs earliest in the week. |
5 3 6 2 7 2 5 3 5 4 0 4 0 6 | 3 |
Thought Process
If the sum of two numbers is greater than 8, compare them and store the current index i in an answer variable if there's a new maximum value. After the for loop ends, output the answer variable.
Sample Code-ZeroJudge B146: Time
#include <iostream>
using namespace std;
int main() {
cin.sync_with_stdio(0);
cin.tie(0);
int max = -999, ans = 0;
for (int i = 1; i<=7; i++)
{
int a, b;
cin >> a >> b;
int hour = a+b;
if (hour > 8)
{
if (hour > max)
{
max = hour;
ans = i;
}
}
}
cout << ans << "\n";
}
//ZeroJudge B146
//Dr. SeanXD