結果

問題 No.345 最小チワワ問題
ユーザー h_tyokinuhatah_tyokinuhata
提出日時 2016-02-27 02:44:19
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 691 bytes
コンパイル時間 2,011 ms
コンパイル使用メモリ 74,948 KB
実行使用メモリ 57,716 KB
最終ジャッジ日時 2023-10-24 18:11:03
合計ジャッジ時間 7,064 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 122 ms
57,524 KB
testcase_01 AC 123 ms
57,440 KB
testcase_02 AC 122 ms
57,444 KB
testcase_03 AC 125 ms
57,472 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 AC 125 ms
57,296 KB
testcase_11 WA -
testcase_12 AC 123 ms
57,416 KB
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 AC 121 ms
57,420 KB
testcase_20 AC 123 ms
57,052 KB
testcase_21 AC 122 ms
57,264 KB
testcase_22 AC 128 ms
57,376 KB
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 AC 121 ms
57,156 KB
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		String S = sc.next();
		
		String comp = S;
		
		int flag = 0;
		
		for(int i = 0; i < S.length(); i++) {
			if(S.substring(i, i + 1).equals("c")) {
				S = S.substring(i);
				comp = S;
				//System.out.println(S);
				S = S.substring(S.indexOf("w") + 1);
				//System.out.println(S);
				if(S.indexOf("w") == -1) {
					flag = 1;
					break;
				} else {
					S = S.substring(S.indexOf("w") + 1);
					//System.out.println(S);	
				}
			}
		}
		
		if(flag == 0) {
			System.out.println(comp.length() - S.length());
		} else {
			System.out.println(-1);	
		}
	}
}
0