結果

問題 No.150 "良問"(良問とは言っていない
ユーザー silviasetitech
提出日時 2020-03-15 16:11:19
言語 Java
(openjdk 23)
結果
AC  
実行時間 215 ms / 5,000 ms
コード長 1,700 bytes
コンパイル時間 2,139 ms
コンパイル使用メモリ 77,728 KB
実行使用メモリ 54,512 KB
最終ジャッジ日時 2024-11-25 03:17:31
合計ジャッジ時間 6,496 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 20
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author silviase
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        goooodProblem solver = new goooodProblem();
        solver.solve(1, in, out);
        out.close();
    }

    static class goooodProblem {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int q = in.nextInt();
            for (int i = 0; i < q; i++) {
                out.println(calc(in.next()));
            }
        }

        int calc(String s) {
            int res = Integer.MAX_VALUE;
            for (int i = 0; i <= s.length() - 11; i++) {
                for (int j = i + 4; j <= s.length() - 7; j++) {
                    int cmp = 0;

                    String good = "good";
                    String problem = "problem";
                    for (int k = 0; k < 4; k++) {
                        if (s.charAt(i + k) != good.charAt(k)) {
                            cmp++;
                        }
                    }
                    for (int k = 0; k < 7; k++) {
                        if (s.charAt(j + k) != problem.charAt(k)) {
                            cmp++;
                        }
                    }
                    res = Math.min(res, cmp);
                }
            }
            return res;
        }

    }
}

0