結果
問題 |
No.791 うし数列
|
ユーザー |
![]() |
提出日時 | 2019-02-22 21:53:22 |
言語 | Java (openjdk 23) |
結果 |
AC
|
実行時間 | 135 ms / 2,000 ms |
コード長 | 610 bytes |
コンパイル時間 | 2,118 ms |
コンパイル使用メモリ | 74,364 KB |
実行使用メモリ | 54,296 KB |
最終ジャッジ日時 | 2024-11-25 07:53:07 |
合計ジャッジ時間 | 5,062 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 15 |
ソースコード
import java.util.Scanner; public class Main { static public void main(String[]args) throws Exception { Scanner sc = new Scanner(System.in); String n = sc.next(); printAns(n); } static void printAns(String s) throws Exception { if( isValid(s) ) { int ans = s.length() -1; System.out.println(ans); } else { System.out.println(-1); } } static boolean isValid(String s) throws Exception { if(s.charAt(0) != '1') return false; if(!s.contains("3")) return false; for(int i=1; i<s.length(); i++) { char c = s.charAt(i); if( c != '3') return false; } return true; } }