結果

問題 No.791 うし数列
ユーザー kohaku_kohakukohaku_kohaku
提出日時 2019-02-22 21:43:41
言語 Java19
(openjdk 21)
結果
WA  
実行時間 -
コード長 708 bytes
コンパイル時間 5,826 ms
コンパイル使用メモリ 74,072 KB
実行使用メモリ 58,180 KB
最終ジャッジ日時 2023-08-16 17:09:08
合計ジャッジ時間 5,631 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 112 ms
55,576 KB
testcase_01 AC 101 ms
55,732 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 AC 101 ms
55,812 KB
testcase_05 WA -
testcase_06 AC 104 ms
55,804 KB
testcase_07 AC 105 ms
55,968 KB
testcase_08 AC 103 ms
55,744 KB
testcase_09 AC 103 ms
53,896 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 AC 100 ms
55,928 KB
testcase_13 AC 102 ms
55,500 KB
testcase_14 AC 98 ms
55,640 KB
testcase_15 AC 100 ms
55,524 KB
testcase_16 AC 100 ms
55,640 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.ArrayList;
import java.util.List;
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 {
		List<Character> list = new ArrayList<>();
		for(int i=0; i<s.length(); i++) {
			char c = s.charAt(i);
			if(c == '1' || c == '3') {
				//nothing
			} else {
				list.add(c);
			}
		}
		if(list.size() == 0) return true;
		return false;
	}
}
0