結果

問題 No.150 "良問"(良問とは言っていない
ユーザー くれちー
提出日時 2017-02-06 20:42:49
言語 C90
(gcc 12.3.0)
結果
AC  
実行時間 5 ms / 5,000 ms
コード長 642 bytes
コンパイル時間 265 ms
コンパイル使用メモリ 21,120 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-10-11 02:10:49
合計ジャッジ時間 1,051 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 20
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.c: In function ‘main’:
main.c:12:9: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   12 |         scanf("%d", &t);
      |         ^~~~~~~~~~~~~~~
main.c:16:17: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   16 |                 scanf("%s", s);
      |                 ^~~~~~~~~~~~~~

ソースコード

diff #

#include <stdio.h>
#include <string.h>
#define rep(i, n) for (i = 0; i < n; i++)
#define min(a, b) (a < b ? a : b)
#define inf 1145141919

int main() {
	char *good = "good";
	char *problem = "problem";

	int i, j, t;
	scanf("%d", &t);

	rep(i, t) {
		char s[101];
		scanf("%s", s);
		int len = strlen(s);
		int top1 = 0, top2 = len - 7;
		int ans = inf;
		while (top1 <= len - 11) {
			int t1 = 0, t2 = 0;
			rep(j, 4) if (s[top1 + j] != good[j]) t1++;
			rep(j, 7) if (s[top2 + j] != problem[j]) t2++;
			ans = min(ans, t1 + t2);
			if (top1 + 4 == top2) { top1++; top2 = len - 7; }
			else top2--;
		}
		printf("%d\n", ans);
	}
	return 0;
}
0