Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class exercises {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- int maxPoints = Integer.MIN_VALUE;
- String best = "";
- int participants = Integer.parseInt(scanner.nextLine());
- for (int i = 1; i <= participants; i++) {
- String name = scanner.nextLine();
- String input = scanner.nextLine();
- int allPoints = 0;
- while (!input.equals("Stop")){
- int grade = Integer.parseInt(input);
- allPoints += grade;
- input = scanner.nextLine();
- }
- if (allPoints > maxPoints){
- maxPoints = allPoints;
- best = name;
- }
- if (input.equals("Stop")){
- System.out.printf("%s has %d points.%n", name, allPoints );
- if (allPoints >= maxPoints){
- System.out.printf("%s is the new number 1!%n", best);
- }
- allPoints = 0;
- continue;
- }
- }
- System.out.printf("%s won competition with %d points!", best, maxPoints);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement