結果
問題 |
No.884 Eat and Add
|
ユーザー |
|
提出日時 | 2020-08-04 19:56:56 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 5 ms / 1,000 ms |
コード長 | 617 bytes |
コンパイル時間 | 684 ms |
コンパイル使用メモリ | 70,596 KB |
最終ジャッジ日時 | 2025-01-12 14:24:09 |
ジャッジサーバーID (参考情報) |
judge5 / judge6 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 9 |
ソースコード
#include <iostream> #include <algorithm> #include <string> void solve() { std::string s; std::cin >> s; int n = s.length(); std::reverse(s.begin(), s.end()); int ans = 0, carry = 0; for (int i = 0; i < n; ++i) { if (s[i] == '0') { s[i] += carry; carry = 0; } if (s[i] == '1' && !carry) { ++ans; if (i + 1 < n && s[i + 1] == '1') carry = 1; } } ans += carry; std::cout << ans << "\n"; } int main() { std::cin.tie(nullptr); std::ios::sync_with_stdio(false); solve(); return 0; }