結果
問題 | No.150 "良問"(良問とは言っていない |
ユーザー | jp_ste |
提出日時 | 2015-03-29 06:01:19 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 245 ms / 5,000 ms |
コード長 | 1,455 bytes |
コンパイル時間 | 2,117 ms |
コンパイル使用メモリ | 77,524 KB |
実行使用メモリ | 47,836 KB |
最終ジャッジ日時 | 2024-04-19 09:24:51 |
合計ジャッジ時間 | 6,483 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 171 ms
44,928 KB |
testcase_01 | AC | 112 ms
41,040 KB |
testcase_02 | AC | 115 ms
41,304 KB |
testcase_03 | AC | 118 ms
39,888 KB |
testcase_04 | AC | 117 ms
41,828 KB |
testcase_05 | AC | 143 ms
41,772 KB |
testcase_06 | AC | 245 ms
47,836 KB |
testcase_07 | AC | 113 ms
40,984 KB |
testcase_08 | AC | 126 ms
41,756 KB |
testcase_09 | AC | 131 ms
41,112 KB |
testcase_10 | AC | 168 ms
45,112 KB |
testcase_11 | AC | 176 ms
45,668 KB |
testcase_12 | AC | 153 ms
45,228 KB |
testcase_13 | AC | 162 ms
45,228 KB |
testcase_14 | AC | 179 ms
45,448 KB |
testcase_15 | AC | 186 ms
45,744 KB |
testcase_16 | AC | 144 ms
41,872 KB |
testcase_17 | AC | 157 ms
43,036 KB |
testcase_18 | AC | 199 ms
45,224 KB |
testcase_19 | AC | 203 ms
45,952 KB |
testcase_20 | AC | 213 ms
46,124 KB |
ソースコード
import java.util.Scanner; public class Main { static final String GOOD_STRING = "good"; static final String PROBLEM_STRING = "problem"; static int mAns = Integer.MAX_VALUE; public static void main(String[] args) { Scanner sc = new Scanner(System.in); int N = sc.nextInt(); for(int i=0; i<N; i++) { mAns = Integer.MAX_VALUE; String T = sc.next(); serch(T); System.out.println(mAns); } } private static void serch(String str) { String base = GOOD_STRING; //good for(int i=0; i<=str.length()-base.length(); i++) { String target = str.substring(i, base.length()+i); int n_good = unmatchCharacterNum(target, base); String nextStr = str.substring( base.length()+i); //problem String nextBase = PROBLEM_STRING; for(int j=0; j<=nextStr.length()-nextBase.length(); j++) { String nextTarget = nextStr.substring(j, nextBase.length()+j); int n_problem = unmatchCharacterNum(nextTarget, nextBase); mAns = Math.min(mAns, n_good+n_problem); } } } //一致していない文字の個数を返す。 private static int unmatchCharacterNum(String target, String base) { if(target.equals(base)) { return 0; } if(target.length() != base.length()) { throw new IllegalArgumentException("length is bad"); } int count = 0; for(int i=0; i<target.length(); i++) { if(target.charAt(i) != base.charAt(i)) count++; } return count; } }