結果
問題 | No.345 最小チワワ問題 |
ユーザー | mits58 |
提出日時 | 2016-07-02 18:27:37 |
言語 | Java (openjdk 23) |
結果 |
AC
|
実行時間 | 129 ms / 2,000 ms |
コード長 | 553 bytes |
コンパイル時間 | 2,560 ms |
コンパイル使用メモリ | 74,476 KB |
実行使用メモリ | 54,364 KB |
最終ジャッジ日時 | 2024-09-25 11:50:32 |
合計ジャッジ時間 | 7,584 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 29 |
ソースコード
import java.util.Scanner; public class Main{ public static void main(String[] args){ Scanner sc=new Scanner(System.in); while(sc.hasNext()){ String s=sc.next(); int ans=Integer.MAX_VALUE; for(int i=0;i<s.length();i++){ if(s.charAt(i)=='c'){ int l=1; int c=0; for(int j=i;j<s.length();j++){ if(s.charAt(j)=='w') c++; if(c==2){ l=j-i+1; break; } } if(l>=3) ans=Math.min(ans,l); } } if(ans==Integer.MAX_VALUE) System.out.println(-1); else System.out.println(ans); } } }