結果

問題 No.495 (^^*) Easy
ユーザー kohaku_kohakukohaku_kohaku
提出日時 2019-02-19 16:55:01
言語 Java21
(openjdk 21)
結果
AC  
実行時間 251 ms / 2,000 ms
コード長 1,198 bytes
コンパイル時間 2,020 ms
コンパイル使用メモリ 83,784 KB
実行使用メモリ 49,628 KB
最終ジャッジ日時 2024-04-20 13:36:24
合計ジャッジ時間 3,797 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 126 ms
41,560 KB
testcase_01 AC 131 ms
42,324 KB
testcase_02 AC 135 ms
42,216 KB
testcase_03 AC 138 ms
42,252 KB
testcase_04 AC 132 ms
41,564 KB
testcase_05 AC 154 ms
43,028 KB
testcase_06 AC 251 ms
49,628 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
    static final String LEFT_FACE = "(^^*)";
    static final String RIGHT_FACE = "(*^^)";
    static final int LEFT_INDEX = 0;
    static final int RIGHT_INDEX = 1;

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        int [] ans = count(s);
        System.out.println(ans[LEFT_INDEX] + " "+ ans[RIGHT_INDEX]);
    }
    
    static private int[] count(String s) {
        int leftCount = 0;
        int rightCount = 0;
        int [] count = new int [2];
        Queue<Character> q = new LinkedList<>();
        for(int i=0; i<s.length()-1; i++) {
            q.add(s.charAt(i));
        }
        while(!q.isEmpty()) {
            StringBuilder sb = new StringBuilder();
            for(int i=0; i<5; i++) {
                sb.append(q.poll());
            }
            String str = sb.toString();
            if(LEFT_FACE.equals(str)) {
                leftCount++;
            } else if(RIGHT_FACE.equals(str)) {
                rightCount++;
            }
        }
        count[LEFT_INDEX] = leftCount;
        count[RIGHT_INDEX] = rightCount;
        return count;
    }
}
0