結果

問題 No.345 最小チワワ問題
ユーザー eagleeagle
提出日時 2022-06-14 11:08:44
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 869 bytes
コンパイル時間 1,992 ms
コンパイル使用メモリ 75,088 KB
実行使用メモリ 54,796 KB
最終ジャッジ日時 2024-04-10 03:44:01
合計ジャッジ時間 7,075 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 124 ms
54,256 KB
testcase_01 AC 124 ms
54,152 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 AC 111 ms
52,744 KB
testcase_05 AC 124 ms
54,396 KB
testcase_06 AC 125 ms
54,120 KB
testcase_07 AC 125 ms
54,128 KB
testcase_08 AC 122 ms
54,588 KB
testcase_09 AC 109 ms
52,716 KB
testcase_10 AC 123 ms
53,828 KB
testcase_11 AC 123 ms
54,220 KB
testcase_12 AC 127 ms
53,996 KB
testcase_13 AC 123 ms
54,132 KB
testcase_14 AC 125 ms
54,264 KB
testcase_15 AC 122 ms
53,828 KB
testcase_16 AC 125 ms
54,400 KB
testcase_17 WA -
testcase_18 WA -
testcase_19 AC 126 ms
54,512 KB
testcase_20 AC 124 ms
54,304 KB
testcase_21 AC 123 ms
53,940 KB
testcase_22 AC 122 ms
53,916 KB
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 AC 124 ms
54,012 KB
testcase_29 AC 123 ms
54,208 KB
testcase_30 AC 126 ms
54,796 KB
testcase_31 AC 126 ms
54,208 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[0]) {
				idx = 1;
				flg = true;
				ans = 0;
			} else if(c == chiwawa[idx]) {
				idx++;
			}
			if(flg) {
				ans++;
			}
			//チワワ列が終わったか
			if(idx == chiwawa.length) {
				finish = true;
				break;
			}
		}
		if(finish) {
			System.out.println(ans);
		} else {
			System.out.println(-1);
		}
	}
}
0