結果

問題 No.884 Eat and Add
ユーザー ks2mks2m
提出日時 2019-09-13 22:05:01
言語 Java21
(openjdk 21)
結果
AC  
実行時間 236 ms / 1,000 ms
コード長 649 bytes
コンパイル時間 2,099 ms
コンパイル使用メモリ 72,404 KB
実行使用メモリ 58,668 KB
最終ジャッジ日時 2023-09-17 14:23:44
合計ジャッジ時間 5,017 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 119 ms
55,820 KB
testcase_01 AC 121 ms
55,672 KB
testcase_02 AC 123 ms
55,732 KB
testcase_03 AC 234 ms
58,520 KB
testcase_04 AC 233 ms
58,200 KB
testcase_05 AC 236 ms
58,260 KB
testcase_06 AC 231 ms
58,336 KB
testcase_07 AC 229 ms
58,528 KB
testcase_08 AC 224 ms
58,520 KB
testcase_09 AC 229 ms
58,668 KB
testcase_10 AC 117 ms
55,520 KB
testcase_11 AC 117 ms
55,736 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		String n = sc.next();
		sc.close();

		StringBuilder sb = new StringBuilder(n);
		sb.reverse().append("0");
		int ans = 0;
		boolean flg = false;
		for (int i = 0; i < n.length(); i++) {
			if (flg) {
				if (sb.charAt(i) == '0') {
					ans++;
					if (sb.charAt(i + 1) == '0') {
						flg = false;
					}
				}
			} else {
				if (sb.charAt(i) == '1') {
					ans++;
					if (sb.charAt(i + 1) == '1') {
						flg = true;
					}
				}
			}
		}
		if (flg) {
			ans++;
		}
		System.out.println(ans);
	}
}
0