結果
問題 |
No.345 最小チワワ問題
|
ユーザー |
![]() |
提出日時 | 2021-10-04 18:07:46 |
言語 | Java (openjdk 23) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,413 bytes |
コンパイル時間 | 4,024 ms |
コンパイル使用メモリ | 79,168 KB |
実行使用メモリ | 41,612 KB |
最終ジャッジ日時 | 2024-07-22 18:35:39 |
合計ジャッジ時間 | 9,222 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 19 WA * 10 |
ソースコード
package com.mycompany.app; import java.util.Scanner; import java.util.ArrayList; import java.util.Collections; import java.util.HashSet; import java.util.HashMap; import java.util.regex.Pattern; import java.util.regex.Matcher; public class App { // strをseparatorで分割してArrayList<Integer>へ変換 public static ArrayList<Integer> splitToArrayList(String str, String separator){ ArrayList<Integer> ans = new ArrayList<Integer>(); String[] separated_str = str.split(" "); for(int i = 0; i < separated_str.length; i++){ ans.add(Integer.valueOf(separated_str[i])); } return ans; } public static void main( String[] args ) { Scanner scan = new Scanner(System.in); String first_line = scan.nextLine(); scan.close(); // c, w, wがこの順で現れる正規表現 Pattern p = Pattern.compile("(c[^c]*w[^c]*w)"); Matcher m = p.matcher(first_line); // 文字列の最大値は100なので,デフォルト値は101 int min_length = 101; while(m.find()){ int matching_str_length = m.group().length(); if(matching_str_length < min_length){ min_length = matching_str_length; } } if(min_length == 101) System.out.println(-1); else System.out.println(min_length); return; } }