結果

問題 No.150 "良問"(良問とは言っていない
ユーザー haruki_57haruki_57
提出日時 2015-02-14 12:36:35
言語 Java21
(openjdk 21)
結果
AC  
実行時間 266 ms / 5,000 ms
コード長 998 bytes
コンパイル時間 3,440 ms
コンパイル使用メモリ 77,816 KB
実行使用メモリ 47,776 KB
最終ジャッジ日時 2024-04-19 09:23:24
合計ジャッジ時間 8,598 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 189 ms
46,088 KB
testcase_01 AC 133 ms
41,436 KB
testcase_02 AC 132 ms
41,336 KB
testcase_03 AC 133 ms
41,696 KB
testcase_04 AC 132 ms
41,408 KB
testcase_05 AC 141 ms
41,868 KB
testcase_06 AC 266 ms
47,776 KB
testcase_07 AC 131 ms
41,704 KB
testcase_08 AC 137 ms
41,788 KB
testcase_09 AC 141 ms
41,704 KB
testcase_10 AC 190 ms
45,912 KB
testcase_11 AC 222 ms
46,704 KB
testcase_12 AC 185 ms
45,284 KB
testcase_13 AC 192 ms
45,920 KB
testcase_14 AC 229 ms
47,412 KB
testcase_15 AC 227 ms
46,552 KB
testcase_16 AC 165 ms
42,444 KB
testcase_17 AC 169 ms
45,028 KB
testcase_18 AC 230 ms
46,516 KB
testcase_19 AC 237 ms
47,048 KB
testcase_20 AC 236 ms
47,368 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;


public class GO {

    /**
     * @param args
     */
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int T = sc.nextInt();
        String s=null;
        String good ="good",problem="problem";

        for (int t = 0; t < T; t++) {
            int ans = 1<<29;
            s = sc.next();
            for (int i = 0; i < s.length(); i++) {
                for (int j = i+good.length(); j <= s.length()-problem.length(); j++) {
                    int sum = 0;
                    sum = len(good,s.substring(i,i+good.length())) + len(problem,s.substring(j,j+problem.length()));
                    ans = Math.min(ans, sum);
                }
            }
            System.out.println(ans);
        }
        
        
    }
    static int len(String s,String t){
        int res = 0;
        for (int i = 0; i < s.length(); i++) {
            res += s.charAt(i)==t.charAt(i)?0:1;
        }
        return res;
    }
}
0