結果

問題 No.495 (^^*) Easy
ユーザー kohaku_kohaku
提出日時 2019-02-19 16:55:01
言語 Java
(openjdk 23)
結果
AC  
実行時間 308 ms / 2,000 ms
コード長 1,198 bytes
コンパイル時間 2,357 ms
コンパイル使用メモリ 80,128 KB
実行使用メモリ 50,064 KB
最終ジャッジ日時 2024-10-12 09:07:02
合計ジャッジ時間 4,289 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 7
権限があれば一括ダウンロードができます

ソースコード

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