結果

問題 No.884 Eat and Add
ユーザー ks2m
提出日時 2019-09-13 21:58:17
言語 Java
(openjdk 23)
結果
WA  
実行時間 -
コード長 590 bytes
コンパイル時間 2,071 ms
コンパイル使用メモリ 74,448 KB
実行使用メモリ 56,988 KB
最終ジャッジ日時 2024-07-04 04:14:19
合計ジャッジ時間 4,978 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2 WA * 1
other AC * 2 WA * 7
権限があれば一括ダウンロードができます

ソースコード

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 (sb.charAt(i) == '1') {
				if (!flg) {
					ans++;
					flg = true;
				}
			} else {
				if (flg) {
					ans++;
					if (sb.charAt(i + 1) == '0') {
						flg = false;
					}
				}
			}
		}
		if (flg) {
			ans++;
		}
		System.out.println(ans);
	}
}
0