結果
問題 |
No.150 "良問"(良問とは言っていない
|
ユーザー |
![]() |
提出日時 | 2015-03-29 05:28:55 |
言語 | Java (openjdk 23) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,872 bytes |
コンパイル時間 | 1,862 ms |
コンパイル使用メモリ | 78,608 KB |
実行使用メモリ | 46,188 KB |
最終ジャッジ日時 | 2024-07-03 22:32:45 |
合計ジャッジ時間 | 6,085 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 4 WA * 16 |
ソースコード
package No150; import java.util.Scanner; public class Main { static final String GOOD_STRING = "good"; static final String PROBLEM_STRING = "problem"; static int mMinLengthOfGood = Integer.MAX_VALUE; static int mMinLengthOfProblem = Integer.MAX_VALUE; 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++) { mMinLengthOfGood = Integer.MAX_VALUE; mMinLengthOfProblem = Integer.MAX_VALUE; mAns = Integer.MAX_VALUE; String T = sc.next(); serchGood(T); System.out.println(mAns); } } private static void serchGood(String str) { String base = GOOD_STRING; for(int i=0; i<=str.length()-base.length(); i++) { String target = str.substring(i, base.length()+i); int num = unmatchCharacterNum(target, base); mMinLengthOfGood = Math.min(mMinLengthOfGood, num); String nextStr = str.substring( base.length()+i); serchProblem( nextStr ); } } private static void serchProblem(String str) { String base = PROBLEM_STRING; if(str.length() < base.length() ) return; for(int i=0; i<=str.length()-base.length(); i++) { String target = str.substring(i, base.length()+i); int num = unmatchCharacterNum(target, base); mMinLengthOfProblem = Math.min(mMinLengthOfProblem, num); mAns = Math.min(mAns, mMinLengthOfGood + mMinLengthOfProblem); } } //一致していない文字の個数を返す。 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; } }