結果

問題 No.345 最小チワワ問題
ユーザー monburan_0401monburan_0401
提出日時 2018-09-11 19:04:45
言語 C
(gcc 12.3.0)
結果
AC  
実行時間 1 ms / 2,000 ms
コード長 1,252 bytes
コンパイル時間 1,153 ms
コンパイル使用メモリ 29,568 KB
実行使用メモリ 6,676 KB
最終ジャッジ日時 2024-04-08 10:57:08
合計ジャッジ時間 1,744 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,676 KB
testcase_01 AC 1 ms
6,676 KB
testcase_02 AC 1 ms
6,676 KB
testcase_03 AC 1 ms
6,676 KB
testcase_04 AC 1 ms
6,676 KB
testcase_05 AC 1 ms
6,676 KB
testcase_06 AC 1 ms
6,676 KB
testcase_07 AC 1 ms
6,676 KB
testcase_08 AC 1 ms
6,676 KB
testcase_09 AC 1 ms
6,676 KB
testcase_10 AC 1 ms
6,676 KB
testcase_11 AC 1 ms
6,676 KB
testcase_12 AC 1 ms
6,676 KB
testcase_13 AC 1 ms
6,676 KB
testcase_14 AC 1 ms
6,676 KB
testcase_15 AC 1 ms
6,676 KB
testcase_16 AC 1 ms
6,676 KB
testcase_17 AC 1 ms
6,676 KB
testcase_18 AC 1 ms
6,676 KB
testcase_19 AC 1 ms
6,676 KB
testcase_20 AC 1 ms
6,676 KB
testcase_21 AC 1 ms
6,676 KB
testcase_22 AC 1 ms
6,676 KB
testcase_23 AC 1 ms
6,676 KB
testcase_24 AC 1 ms
6,676 KB
testcase_25 AC 1 ms
6,676 KB
testcase_26 AC 1 ms
6,676 KB
testcase_27 AC 1 ms
6,676 KB
testcase_28 AC 1 ms
6,676 KB
testcase_29 AC 1 ms
6,676 KB
testcase_30 AC 1 ms
6,676 KB
testcase_31 AC 1 ms
6,676 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;				//	wの回数をカウント
	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つないなら終わり
            if(minL > goal - start + 1){
                minL = goal - start + 1;
            }
		}
	}
    if(minL == 1000){
        printf("-1\n");
    }else{
        printf("%d\n",minL);
    }
	return 0;
}
0