結果

問題 No.495 (^^*) Easy
ユーザー kohaku_kohakukohaku_kohaku
提出日時 2019-02-19 16:55:01
言語 Java21
(openjdk 21)
結果
AC  
実行時間 275 ms / 2,000 ms
コード長 1,198 bytes
コンパイル時間 2,336 ms
コンパイル使用メモリ 79,916 KB
実行使用メモリ 48,296 KB
最終ジャッジ日時 2023-08-02 13:33:44
合計ジャッジ時間 4,348 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 144 ms
40,308 KB
testcase_01 AC 142 ms
40,728 KB
testcase_02 AC 141 ms
40,368 KB
testcase_03 AC 141 ms
40,420 KB
testcase_04 AC 145 ms
40,624 KB
testcase_05 AC 180 ms
41,708 KB
testcase_06 AC 275 ms
48,296 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