結果

問題 No.345 最小チワワ問題
ユーザー kenji_shioyakenji_shioya
提出日時 2016-05-29 07:45:14
言語 Java21
(openjdk 21)
結果
AC  
実行時間 131 ms / 2,000 ms
コード長 741 bytes
コンパイル時間 4,094 ms
コンパイル使用メモリ 78,736 KB
実行使用メモリ 57,608 KB
最終ジャッジ日時 2023-10-26 03:55:05
合計ジャッジ時間 8,690 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 124 ms
57,276 KB
testcase_01 AC 126 ms
57,052 KB
testcase_02 AC 126 ms
57,304 KB
testcase_03 AC 128 ms
57,220 KB
testcase_04 AC 127 ms
57,608 KB
testcase_05 AC 129 ms
57,288 KB
testcase_06 AC 127 ms
57,228 KB
testcase_07 AC 128 ms
57,332 KB
testcase_08 AC 125 ms
57,096 KB
testcase_09 AC 128 ms
57,320 KB
testcase_10 AC 126 ms
57,316 KB
testcase_11 AC 128 ms
57,304 KB
testcase_12 AC 128 ms
57,296 KB
testcase_13 AC 127 ms
57,300 KB
testcase_14 AC 131 ms
57,252 KB
testcase_15 AC 127 ms
57,316 KB
testcase_16 AC 128 ms
57,220 KB
testcase_17 AC 127 ms
57,324 KB
testcase_18 AC 126 ms
57,300 KB
testcase_19 AC 124 ms
57,280 KB
testcase_20 AC 126 ms
57,276 KB
testcase_21 AC 123 ms
57,244 KB
testcase_22 AC 126 ms
57,284 KB
testcase_23 AC 124 ms
57,304 KB
testcase_24 AC 126 ms
57,256 KB
testcase_25 AC 121 ms
57,280 KB
testcase_26 AC 127 ms
57,240 KB
testcase_27 AC 120 ms
57,144 KB
testcase_28 AC 126 ms
57,580 KB
testcase_29 AC 126 ms
57,320 KB
testcase_30 AC 127 ms
57,312 KB
testcase_31 AC 125 ms
57,448 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Exercise31{
  public static void main (String[] args){

    Scanner sc = new Scanner(System.in);

    String str = sc.next();
    char[] charArray = str.toCharArray();

    int min = charArray.length;
    boolean flag = false;

    for (int a = 0; a < charArray.length; a++){
      if (charArray[a] == 'c'){
        int w = 0;
        forW: for (int b = a + 1; b < charArray.length; b++){
          if (charArray[b] == 'w'){
            w++;
          }
          if (w == 2){
            flag = true;
            min = Math.min(min, (b + 1) - a);
            break forW;
          }
        }
      }
    }

    if (flag){
      System.out.println(min);
    }else{
      System.out.println(-1);
    }
  }
}
0