結果

問題 No.345 最小チワワ問題
ユーザー eagleeagle
提出日時 2022-06-14 11:05:23
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 811 bytes
コンパイル時間 2,392 ms
コンパイル使用メモリ 74,164 KB
実行使用メモリ 56,720 KB
最終ジャッジ日時 2024-04-10 03:35:11
合計ジャッジ時間 7,480 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 125 ms
54,192 KB
testcase_01 AC 126 ms
53,928 KB
testcase_02 AC 130 ms
54,244 KB
testcase_03 AC 128 ms
54,028 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 AC 126 ms
54,036 KB
testcase_08 AC 127 ms
53,860 KB
testcase_09 AC 123 ms
53,992 KB
testcase_10 AC 130 ms
54,348 KB
testcase_11 AC 125 ms
53,980 KB
testcase_12 AC 127 ms
53,824 KB
testcase_13 AC 129 ms
54,064 KB
testcase_14 WA -
testcase_15 AC 128 ms
53,868 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 AC 126 ms
54,148 KB
testcase_20 AC 126 ms
54,292 KB
testcase_21 AC 126 ms
53,960 KB
testcase_22 AC 126 ms
54,216 KB
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 AC 127 ms
53,868 KB
testcase_29 WA -
testcase_30 WA -
testcase_31 AC 126 ms
54,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		//与えられる文字列
		String S = sc.next();
		char[] chiwawa = {'c', 'w', 'w'};
		//配列chiwawaを参照するインデックス
		int idx = 0;
		//チワワ列を数える
		int ans = 0;
		//チワワ列が始まったか
		boolean flg = false;
		boolean finish = false;
		for(int i = 0; i < S.length(); i++) {
			char c = S.charAt(i);
			if(c == chiwawa[idx]) {
				idx++;
				flg = true;
			}
			if(flg) {
				ans++;
			}
			//チワワ列が終わったか
			if(idx == chiwawa.length) {
				finish = true;
				break;
			}
		}
		if(finish) {
			System.out.println(ans);
		} else {
			System.out.println(-1);
		}
	}
}
0