結果
| 問題 |
No.150 "良問"(良問とは言っていない
|
| コンテスト | |
| ユーザー |
jp_ste
|
| 提出日時 | 2015-03-29 06:01:19 |
| 言語 | Java (openjdk 23) |
| 結果 |
AC
|
| 実行時間 | 266 ms / 5,000 ms |
| コード長 | 1,455 bytes |
| コンパイル時間 | 2,417 ms |
| コンパイル使用メモリ | 77,244 KB |
| 実行使用メモリ | 47,628 KB |
| 最終ジャッジ日時 | 2024-10-11 01:54:19 |
| 合計ジャッジ時間 | 6,410 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 20 |
ソースコード
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;
}
}
jp_ste