結果

問題 No.672 最長AB列
ユーザー kohaku_kohaku
提出日時 2018-04-13 23:17:58
言語 Java
(openjdk 23)
結果
WA  
実行時間 -
コード長 950 bytes
コンパイル時間 2,604 ms
コンパイル使用メモリ 78,552 KB
実行使用メモリ 42,348 KB
最終ジャッジ日時 2024-06-27 17:11:03
合計ジャッジ時間 7,806 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample WA * 3
other WA * 6 TLE * 1 -- * 9
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        int ans = function(s);
        System.out.println(ans);
    }
    
    static int function(String s) {
        for(int i = s.length(); i >=0; i--) {
            for(int j = 0; j < s.length()-i+1; j++) {
                String tmp = s.substring(j,i+j);
                if(judge(tmp)) return i;
            }
        }
        return 0;
    }
    
    static boolean judge(String s) {
        int A = count(s,'A');
        int B = count(s,'B');
System.out.println("A="+A + " B="+B);
        if(A == B) {
            return true;
        } else {
            return false;
        }
    }
    
    static int count(String s, char c) {
        int count = 0;
        for(int i = 0; i <s.length(); i++) {
            if(s.charAt(i) == c) count++;
        }
        return count;
    }
}
0