結果

問題 No.345 最小チワワ問題
ユーザー monburan_0401monburan_0401
提出日時 2018-09-10 00:08:37
言語 C
(gcc 12.3.0)
結果
WA  
実行時間 -
コード長 830 bytes
コンパイル時間 587 ms
コンパイル使用メモリ 27,512 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-26 00:36:49
合計ジャッジ時間 2,384 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 0 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 AC 0 ms
4,380 KB
testcase_08 AC 0 ms
4,376 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 0 ms
4,380 KB
testcase_12 AC 1 ms
4,376 KB
testcase_13 AC 1 ms
4,380 KB
testcase_14 WA -
testcase_15 AC 0 ms
4,380 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 AC 1 ms
4,376 KB
testcase_20 AC 1 ms
4,376 KB
testcase_21 AC 1 ms
4,380 KB
testcase_22 AC 1 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,376 KB
testcase_29 WA -
testcase_30 WA -
testcase_31 AC 1 ms
4,376 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の回数をカウント
	
	scanf("%s",S);
	
	start = 1000; goal = 1000;	//	ありえない数字を置いておく
	for(int i = 0; S[i] != 0; i++){
		if(S[i] == 'c'){		//	計測開始
			start = i;
			break;
		}
	}
	if(start == 1000){		//	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{
		printf("%d\n",goal - start + 1);
		return 0;	
	}
	
}
0