結果
| 問題 |
No.150 "良問"(良問とは言っていない
|
| コンテスト | |
| ユーザー |
TLwiegehtt
|
| 提出日時 | 2015-07-15 01:06:56 |
| 言語 | C90 (gcc 12.3.0) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 5,000 ms |
| コード長 | 1,122 bytes |
| コンパイル時間 | 434 ms |
| コンパイル使用メモリ | 22,144 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-10-11 01:55:25 |
| 合計ジャッジ時間 | 1,127 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 20 |
コンパイルメッセージ
main.c: In function ‘main’:
main.c:7:9: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
7 | scanf("%d", &n);
| ^~~~~~~~~~~~~~~
main.c:19:17: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
19 | scanf("%s", s);
| ^~~~~~~~~~~~~~
ソースコード
#include <stdio.h>
#include <string.h>
int main(void){
int in, n;
scanf("%d", &n);
for(in=0;in<n;in++){
char s[110];
const char good[] = "good";
const char problem[] = "problem";
int i;
int hitGood[110]={0};
int hitProblem[110]={0};
int sLen, gLen,pLen;
int ans = 99999;
scanf("%s", s);
sLen = strlen(s);
gLen = strlen(good);
pLen = strlen(problem);
for(i=0;i<sLen;i++){
int j;
int hit=0;
for( j=0 ; j < gLen ; j++ ){
if(s[i+j] == '\0'){hit = 0; break;}
if( good[j] == s[i+j]){
hit++;
}
}
hitGood[i] = hit;
hit = 0;
for( j=0 ; j < pLen ; j++ ){
if(s[i+j] == '\0'){hit = 0; break;}
if( problem[j] == s[i+j]){
hit++;
}
}
hitProblem[i] = hit;
}
for(i=0;i<sLen;i++){
int j,cnt;
int tmpMinCnt = 99999;
cnt = (gLen-hitGood[i]);
for(j=(i+gLen); (j+pLen-1)< sLen;j++){
int tmp = (pLen - hitProblem[j]);
if( tmp < tmpMinCnt ){
tmpMinCnt = tmp;
}
}
cnt = cnt + tmpMinCnt;
if(cnt < ans ){
ans = cnt;
}
}
printf("%d\n", ans);
}
return 0;
}
TLwiegehtt