結果

問題 No.150 "良問"(良問とは言っていない
ユーザー startcppstartcpp
提出日時 2015-02-12 23:24:13
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 774 bytes
コンパイル時間 427 ms
コンパイル使用メモリ 52,932 KB
実行使用メモリ 4,504 KB
最終ジャッジ日時 2023-09-06 00:12:44
合計ジャッジ時間 1,598 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 6 ms
4,376 KB
testcase_07 WA -
testcase_08 AC 1 ms
4,380 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 AC 2 ms
4,376 KB
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:21:45: warning: ISO C++ forbids converting a string constant to ‘char*’ [-Wwrite-strings]
     int hamming1 = gethamming(S+j, "good", 4);
                                             ^
main.cpp:22:48: warning: ISO C++ forbids converting a string constant to ‘char*’ [-Wwrite-strings]
     int hamming2 = gethamming(S+k, "problem", 7);
                                                ^

ソースコード

diff #

//想定WA解法
#include<iostream>
#include<string.h>
using namespace std;

int gethamming(char *str1, char *str2, int n);

int T;
char S[102];

int main() {
	int i, j, k;
	cin >> T;
	for( i = 0; i < T; i++ ) {
		cin >> S;
		int slen = strlen(S);
		int ans = 114514;
		for( j = 0; j <= slen - 11; j++ ) {
			//k>=j+4、k>=jでやるとWrongAnswerするようにテストケース作った(はずなので後で試す
			for( k = j; k <= slen - 7; k++ ) {
				int hamming1 = gethamming(S+j, "good", 4);
				int hamming2 = gethamming(S+k, "problem", 7);
				ans = min(ans, hamming1 + hamming2);
			}
		}
		cout << ans << endl;
	}
}
int gethamming(char *str1, char *str2, int n) {
	int i, ret = 0;
	for( i = 0; i < n; i++ ) {
		ret += ( str1[i] != str2[i] );
	}
	return ret;
}
0