結果

問題 No.345 最小チワワ問題
ユーザー monburan_0401monburan_0401
提出日時 2018-09-11 18:24:20
言語 C
(gcc 12.3.0)
結果
WA  
実行時間 -
コード長 1,198 bytes
コンパイル時間 414 ms
コンパイル使用メモリ 28,720 KB
実行使用メモリ 4,500 KB
最終ジャッジ日時 2023-09-06 00:13:55
合計ジャッジ時間 1,677 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 0 ms
4,376 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 AC 0 ms
4,380 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 0 ms
4,376 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 0 ms
4,380 KB
testcase_12 AC 0 ms
4,376 KB
testcase_13 AC 1 ms
4,380 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 AC 1 ms
4,380 KB
testcase_20 AC 0 ms
4,376 KB
testcase_21 AC 1 ms
4,380 KB
testcase_22 AC 0 ms
4,380 KB
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 AC 1 ms
4,380 KB
testcase_29 WA -
testcase_30 WA -
testcase_31 AC 1 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

//	与えられた文字列が	c	w	w	の順になる時、その文字の長さ
#include <stdio.h>
int main(void){
	char S[101];		//	1 <= S <= 100
	int start,goal;	//	c 〜 2回目のwまで
	int w;				//	cの回数をカウント
	int moji = 0;		//	入力値の文字数
	int minL = 1000;	//	cww列の最小値
	
	scanf("%s",S);
	
	start = -1;	//	ありえない数字を置いておく
	
	for(int k = 0; S[k] != 0; k++){
		moji++;
	}
	
	for(int j = 0; j < moji; j ++){
	
		for(int i = 0; S[i] != 0; i++){		//	前回のループのstartは除外したい.初期値をマイナスにする
			if( (S[i] == 'c')&&(i > start) ){		//	計測開始		ccwwccwの時どうする?
				start = i;
				break;
			}
		}
		
		if(start == -1){		//	cがないなら終わり
			printf("-1\n");
			return 0;
		}else{
			w = 0;
			for(int j = start; S[j] != 0; j++){
				if(S[j] == 'w'){
					w += 1;
					if(w == 2){		//	wが2回出たら計測終了
						goal = j;
						break;
					}
				}
			}
		}
		
		if(w < 2){		//	wが2つないなら終わり
			printf("-1\n");
			return 0;
		}else{
			if(minL > goal - start + 1){
				minL = goal - start + 1;
			}	
		}
	}
	
	printf("%d\n",minL);
	return 0;
}
0