結果

問題 No.79 過小評価ダメ・ゼッタイ
ユーザー tom_tom_tom
提出日時 2015-11-11 08:51:36
言語 Java
(openjdk 23)
結果
AC  
実行時間 540 ms / 5,000 ms
コード長 3,976 bytes
コンパイル時間 4,231 ms
コンパイル使用メモリ 89,772 KB
実行使用メモリ 48,264 KB
最終ジャッジ日時 2024-06-26 07:45:28
合計ジャッジ時間 12,593 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 22
権限があれば一括ダウンロードができます

ソースコード

diff #

package me.yukicoder;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.InputStream;
import java.io.PrintStream;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;

import static java.util.stream.Collectors.joining;
import static java.util.stream.Collectors.toList;

/**
 * No. 79
 * http://yukicoder.me:8081/problems/202
 * Star 1
 */
public class YukiCoder79 {

    public static void run() {
        Scanner sc = new Scanner(System.in);

        int[] levels = new int[7];
        int n = sc.nextInt();
        for (int i = 0; i < n; i++) {
            int level = sc.nextInt();
            levels[level]++;
        }

        int ans = 0;
        for (int i = 1; i < 7; i++) {
            if (levels[i] >= levels[ans]) {
                ans = i;
            }
        }
        System.out.println(ans);
    }

    private static TestCase getTest1() {
        return new TestCase("2", "5", "2 1 2 3 2");
    }

    private static TestCase getTest2() {
        return new TestCase("3", "5", "1 2 3 3 1");
    }

    private static TestCase getTest3() {
        return new TestCase("6", "10", "5 3 5 6 3 6 2 3 5 6");
    }

    private static TestCase getTest4() {
        return new TestCase("", "");
    }

    private static TestCase getTest5() {
        return new TestCase("", "");
    }
//        return new TestCase("", "");
//        return new TestCase("", "");


    public static void main(String[] args) {
        perform();
    }

    private static boolean LOCAL = System.getenv().keySet().stream().anyMatch(key -> key.startsWith("JAVA_MAIN_CLASS"));

    private static void perform() {
        if (LOCAL) {
            List<TestCase> tests = getTests();
            boolean passed = true;
            int index = 1;
            for (TestCase testCase : getTests()) {
                String input = Arrays.stream(testCase.inputs).collect(joining(System.lineSeparator()));
                InputStream in = new ByteArrayInputStream(input.getBytes());
                System.setIn(in);

                PrintStream sout = System.out;
                ByteArrayOutputStream baos = new ByteArrayOutputStream();
                PrintStream ps = new PrintStream(baos);


                System.setOut(ps);
                try {
                    run();
                } finally {
                    System.setOut(sout);
                }

                System.out.flush();

                String actual = baos.toString().trim();
                String expect = testCase.expect;
                boolean match = expect != null && expect.equals(actual);

                System.out.println("------------------------ " + index++ + "/" + tests.size() + " " + (match ? "PASS" : "FAIL"));
                System.out.println("INPUT: " + input);
                System.out.println("RESULT: " + match);
                System.out.println("EXPECTED: " + expect + ":");
                System.out.println("ACTUAL: " + actual + ":");

                if (!match) passed = false;
            }

            System.out.println("\n==== SUMMARY ==== ");
            System.out.println(passed ? "PASS" : "FAIL");
        } else {
            run();
        }
    }


    public static List<TestCase> getTests() {
        List<TestCase> testCases = new ArrayList<>();
        testCases.add(getTest1());
        testCases.add(getTest2());
        testCases.add(getTest3());
        testCases.add(getTest4());
        testCases.add(getTest5());
        return testCases.stream().filter(t -> !t.ignore()).collect(toList());
    }

    private static class TestCase {
        String expect;
        String[] inputs;

        public TestCase(String expect, String... inputs) {
            this.expect = expect;
            this.inputs = inputs;
        }

        public boolean ignore() {
            return "".equals(expect) && inputs.length == 1 && "".equals(inputs[0]);
        }
    }

}
0