結果
| 問題 |
No.884 Eat and Add
|
| ユーザー |
|
| 提出日時 | 2022-09-24 01:06:47 |
| 言語 | Rust (1.83.0 + proconio) |
| 結果 |
AC
|
| 実行時間 | 4 ms / 1,000 ms |
| コード長 | 706 bytes |
| コンパイル時間 | 11,610 ms |
| コンパイル使用メモリ | 377,960 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-12-22 05:45:25 |
| 合計ジャッジ時間 | 12,756 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 9 |
ソースコード
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);
}