結果

問題 No.345 最小チワワ問題
ユーザー kenji_shioyakenji_shioya
提出日時 2016-05-29 07:23:03
言語 Java21
(openjdk 21)
結果
AC  
実行時間 136 ms / 2,000 ms
コード長 793 bytes
コンパイル時間 3,832 ms
コンパイル使用メモリ 77,892 KB
実行使用メモリ 57,784 KB
最終ジャッジ日時 2023-10-26 03:54:54
合計ジャッジ時間 9,200 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 133 ms
57,216 KB
testcase_01 AC 129 ms
57,408 KB
testcase_02 AC 132 ms
57,320 KB
testcase_03 AC 132 ms
57,248 KB
testcase_04 AC 131 ms
57,272 KB
testcase_05 AC 133 ms
57,784 KB
testcase_06 AC 134 ms
57,056 KB
testcase_07 AC 132 ms
57,280 KB
testcase_08 AC 132 ms
57,232 KB
testcase_09 AC 131 ms
57,228 KB
testcase_10 AC 134 ms
57,300 KB
testcase_11 AC 136 ms
57,244 KB
testcase_12 AC 133 ms
57,528 KB
testcase_13 AC 131 ms
57,300 KB
testcase_14 AC 133 ms
57,592 KB
testcase_15 AC 133 ms
57,284 KB
testcase_16 AC 130 ms
57,260 KB
testcase_17 AC 128 ms
57,228 KB
testcase_18 AC 129 ms
57,308 KB
testcase_19 AC 127 ms
57,452 KB
testcase_20 AC 130 ms
57,064 KB
testcase_21 AC 127 ms
57,300 KB
testcase_22 AC 130 ms
57,224 KB
testcase_23 AC 131 ms
57,280 KB
testcase_24 AC 129 ms
57,292 KB
testcase_25 AC 130 ms
57,236 KB
testcase_26 AC 128 ms
57,552 KB
testcase_27 AC 128 ms
57,332 KB
testcase_28 AC 131 ms
57,268 KB
testcase_29 AC 133 ms
57,304 KB
testcase_30 AC 134 ms
57,276 KB
testcase_31 AC 132 ms
57,264 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'){
        for (int b = a + 1; b < charArray.length; b++){
          if (charArray[b] == 'w'){
            for (int c = b + 1; c < charArray.length; c++){
              if (charArray[c] == 'w'){
                  flag = true;
                  min = Math.min(min, (c + 1) - a);
                }
              }
            }
          }
        }
      }
    if (flag){
      System.out.println(min);
    }else{
      System.out.println(-1);
    }
  }
}
0