day31 417 Unhappy Jinjin (simple simulation)

417. Unhappy Jinjin

Jinjin went to junior high school.

Mother thinks that Jinjin should study harder, so in addition to going to school, Jinjin also participates in various review classes that her mother has registered for her.

In addition, her mother will send her to learn recitation, dance and piano every week.

But Jinjin will be unhappy if he attends classes for more than eight hours a day, and the longer he attends, the more unhappy he will be.

Assume that Jinjin will not be unhappy because of other things, and her unhappiness will not last until the next day.

Please help to check Jinjin’s schedule for next week and see if she will be unhappy next week; if so, which day will be the most unhappy.

Input format The
input file includes seven lines of data, representing the schedule from Monday to Sunday.

Each line contains two non-negative integers less than 10, separated by a space, indicating respectively the time Jinjin is in school and the time her mother arranges for her to be in class.

Output format The
output file contains one line, and this line contains only one number.

If it is not unhappy, output 0. If it does, output the day of the week that is most unhappy (use 1, 2, 3, 4, 5, 6, 7 to indicate Monday, Tuesday, Wednesday, Thursday, Friday, and week respectively) Saturday, Sunday).

If there are two days or more of the same level of unhappiness, the first day of the output time will be output.

Input sample:

5 3
6 2
7 2
5 3
5 4
0 4
0 6

Sample output:

3

Ideas

Simple simulation is enough. Add the time that Jinjin is in school and the time her mother arranges for her to attend class to see if it is greater 8than 8Jinjin. If you are greater than Jinjin, you will be unhappy.

Java code

import java.util.Scanner;

public class Main {
    
    
    public static void main(String[] args) {
    
    
        Scanner scanner = new Scanner(System.in);
        int max = 0;
        int unhappy = 0;
        for(int i = 1;i <= 7;i++){
    
    
            int a = scanner.nextInt();
            int b = scanner.nextInt();
            if(a + b > 8 && a + b > max){
    
    
                max = a + b;
                unhappy = i;
            }
        }
        System.out.println(unhappy);
    }
}

Insert picture description here

Guess you like

Origin blog.csdn.net/YouMing_Li/article/details/114001649