結果

問題 No.345 最小チワワ問題
ユーザー tsunabittsunabit
提出日時 2018-05-27 20:23:13
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 1,483 bytes
コンパイル時間 3,340 ms
コンパイル使用メモリ 72,780 KB
実行使用メモリ 56,164 KB
最終ジャッジ日時 2023-09-11 04:44:41
合計ジャッジ時間 8,957 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 120 ms
56,040 KB
testcase_01 AC 120 ms
55,832 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 AC 121 ms
55,484 KB
testcase_05 AC 121 ms
55,924 KB
testcase_06 WA -
testcase_07 AC 121 ms
56,048 KB
testcase_08 WA -
testcase_09 AC 120 ms
55,608 KB
testcase_10 AC 121 ms
55,828 KB
testcase_11 AC 120 ms
55,684 KB
testcase_12 AC 122 ms
55,976 KB
testcase_13 AC 122 ms
55,776 KB
testcase_14 AC 120 ms
55,648 KB
testcase_15 AC 120 ms
55,796 KB
testcase_16 AC 121 ms
55,448 KB
testcase_17 WA -
testcase_18 WA -
testcase_19 AC 120 ms
55,912 KB
testcase_20 AC 119 ms
55,640 KB
testcase_21 AC 120 ms
56,016 KB
testcase_22 AC 120 ms
55,620 KB
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 AC 120 ms
55,892 KB
testcase_29 AC 120 ms
55,908 KB
testcase_30 AC 120 ms
55,744 KB
testcase_31 AC 120 ms
55,788 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;
import java.util.stream.Stream;

// ***問題文***
// Cさんによれば、ある文字列に 'c', 'w', 'w' がこの順で含まれるとき、その文字列を「チワワ列」であるといいます。
// Cさんは小さなチワワが好きなので、できるだけ長さの小さいチワワ列を見つけたいです。
// 文字列 S が与えられるので、その連続した部分文字列のうちチワワ列となるものの最小の長さを求めてください。
// ***入力***
// S
// 1行目に文字列 S(1≤|S|≤100)が与えられる。
// S は小文字のアルファベットのみで構成される。 
// ***出力***
// S の連続した部分文字列のうちチワワ列となるものの最小の長さを整数で出力してください。
// もしSにチワワ列が含まれない場合は−1を出力してください。
// 最後に改行してください。 

public class No345 {
    public static void main(String[] args) {
        // 標準入力から読み込む際に、Scannerオブジェクトを使う。
        Scanner sc = new Scanner(System.in);
		String s = sc.next();
		int h = 0, e = 0;
		int r = -1;
		for(int i = 0; i < s.length(); i++) {
				if('c' == s.charAt(i)) {
					    h = i;
						e = 0;
				}else if('w' == s.charAt(i) && e == 0) {
						e = 1;
				}else if('w' == s.charAt(i) && e == 1) {
						e = i;
						break;
				}
		}
		System.out.println(e > 1 ? e - h + 1 : -1);

	}
}
0