結果

問題 No.239 にゃんぱすー
ユーザー yagi2
提出日時 2017-04-20 16:36:02
言語 Java
(openjdk 23)
結果
AC  
実行時間 238 ms / 2,000 ms
コード長 1,067 bytes
コンパイル時間 2,688 ms
コンパイル使用メモリ 88,248 KB
実行使用メモリ 47,136 KB
最終ジャッジ日時 2024-07-19 21:06:51
合計ジャッジ時間 9,569 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 33
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = Integer.parseInt(sc.next());

        Map<Integer, Integer> renchon = new HashMap<>();

        for (int i = 0; i < N; i++) {
            for (int j = 0; j < N; j++) {
                String s = sc.next();
                if (s.equals("nyanpass")) {
                    if (!renchon.containsKey(j)) {
                        renchon.put(j, 0);
                    }
                    renchon.put(j, renchon.get(j)+1);
                }
            }
        }

        int cnt = 0;
        for (int i = 0; i < N; i++) {
            if (!renchon.containsKey(i)) continue;
            if (renchon.get(i) == N - 1) cnt++;
        }

        if (cnt != 1) {
            System.out.println("-1");
        } else {
            renchon.forEach((integer, integer2) -> {
                if (integer2 == N -1) System.out.println(integer+1);
            });
        }
    }
}
0