結果

問題 No.667 Mice's Luck(ネズミ達の運)
ユーザー Pump0129Pump0129
提出日時 2018-03-27 10:17:46
言語 Java21
(openjdk 21)
結果
AC  
実行時間 882 ms / 2,000 ms
コード長 1,730 bytes
コンパイル時間 3,901 ms
コンパイル使用メモリ 84,580 KB
実行使用メモリ 71,612 KB
最終ジャッジ日時 2023-09-07 18:55:46
合計ジャッジ時間 8,709 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 126 ms
55,484 KB
testcase_01 AC 125 ms
56,164 KB
testcase_02 AC 129 ms
55,792 KB
testcase_03 AC 136 ms
55,764 KB
testcase_04 AC 189 ms
56,252 KB
testcase_05 AC 329 ms
58,372 KB
testcase_06 AC 679 ms
66,624 KB
testcase_07 AC 882 ms
71,612 KB
testcase_08 AC 847 ms
71,252 KB
testcase_09 AC 856 ms
71,124 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

package net.ipipip0129.yukicoder.no667;

import java.util.Arrays;
import java.util.List;
import java.util.Scanner;
import java.util.stream.Collectors;

public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        List<String> boxlist = Arrays.asList(scan.nextLine().split(""));

        // Stream API 使用
        /*int passCount = boxlist.stream()
                .filter(s -> s.startsWith("o"))
                .collect(Collectors.toList())
                .size();
        int trapCount = boxlist.stream()
                .filter(s -> s.startsWith("x"))
                .collect(Collectors.toList())
                .size();*/

        // Stream API 未使用

        /*int passCount = 0;
        int trapCount = 0;

        for (String box : boxlist) {
            switch (box.charAt(0)) {
                case 'o':
                    passCount++;
                    break;
                case 'x':
                    trapCount++;
                    break;
            }
        }*/

        // Stream API 改良

        int passCount = boxlist.stream()
                .filter(s -> s.startsWith("o"))
                .collect(Collectors.toList())
                .size();
        int trapCount = boxlist.size() - passCount;

        for (String box : boxlist) {
            System.out.println(((double) passCount / (double) (passCount + trapCount)) * 100);
            switch (box.charAt(0)) {
                case 'o':
                    passCount--;
                    break;
                case 'x':
                    trapCount--;
                    break;
            }
        }
    }
}
0