hwangnk1004 / Algorithm

0 stars 0 forks source link

StepByStep #숫자게임 #295

Open hwangnk1004 opened 4 years ago

hwangnk1004 commented 4 years ago

import java.util.Scanner;

public class Main { public static void main(String args[]) {

    Scanner scanner = new Scanner(System.in);

    int n = scanner.nextInt();
    int total[] = new int[n];
    int count = 0;

    while (count < n) {
        int max = 0;
        int arr[] = new int[5];
        for (int i = 0; i < 5; i++) {
            arr[i] = scanner.nextInt();
        }

        for (int i = 0; i < 3; i++) {
            for (int j = i + 1; j < 4; j++) {
                for (int k = j + 1; k < 5; k++) {
                    int sum = arr[i] + arr[j] + arr[k];
                    max = Math.max(max, sum % 10);
                }
            }
        }

        total[count++] = max;

    }

    int x = 0;
    int max = 0;

    for (int j = 0; j < n; j++) {
        max = Math.max(max,total[j]);
        if (max == total[j]) {
            x = j+1;
        }
    }

    System.out.println(x);

}

}