結果

問題 No.884 Eat and Add
ユーザー tonyu0tonyu0
提出日時 2022-09-24 01:06:47
言語 Rust
(1.77.0)
結果
AC  
実行時間 4 ms / 1,000 ms
コード長 706 bytes
コンパイル時間 941 ms
コンパイル使用メモリ 146,296 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-23 21:12:21
合計ジャッジ時間 2,063 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 3 ms
4,376 KB
testcase_04 AC 4 ms
4,380 KB
testcase_05 AC 3 ms
4,376 KB
testcase_06 AC 4 ms
4,380 KB
testcase_07 AC 3 ms
4,380 KB
testcase_08 AC 3 ms
4,376 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

use std::io::*;

fn main() {
    let mut input: String = String::new();
    std::io::stdin().read_to_string(&mut input).ok();
    let mut itr = input.trim().split_whitespace();
    let mut s: Vec<char> = itr.next().unwrap().chars().rev().collect();
    s.push('0');
    let n = s.len();
    s.push('0');

    let mut ans = 0;
    let mut carry = 0;
    for i in 0..n {
        if s[i] == '0' {
            if carry == 1 {
                s[i] = '1';
                carry = 0;
            } else {
            continue;
            }
        }

        if carry == 0 {
            ans += 1;
            if s[i+1] == '1' {
                carry = 1;
            }
        }
    }
    println!("{}", ans);
}
0