Mahmoud_Hawara

Untitled

Jun 20th, 2022
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.14 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #pragma GCC optimize("-Ofast")
  4. #pragma GCC target("sse,sse2,sse3,ssse3,sse4,sse4.2,popcnt,abm,mmx,avx2,tune=native")
  5. #pragma GCC optimize("-ffast-math")
  6. #pragma GCC optimize("-funroll-loops")
  7. #pragma GCC optimize("-funroll-all-loops,-fpeel-loops,-funswitch-loops")
  8. #define IO ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  9. const long long MOD = 1e9 + 7, OO = 1e18;
  10. const double PI = acos(-1);
  11. const int N = 1e6 + 5;
  12. const int dx[4] = {0, 0, 1, -1};
  13. const int dy[4] = {1, -1, 0, 0};
  14.  
  15. long long n, carry, ans;
  16. string num;
  17.  
  18. int main() {
  19.     IO
  20.     cin >> num;
  21.     n = num.size() - 1;
  22.     for (int i = n; i > 0; i--)
  23.     {
  24.         if (num[i] == '0' && carry == 1)
  25.         {
  26.             ans += 2;
  27.         }
  28.         else if (num[i] == '1' && carry == 0)
  29.         {
  30.             ans += 2;
  31.             carry = 1;
  32.         }
  33.         else if (num[i] == '0' && carry == 0)
  34.         {
  35.             ans++;
  36.         }
  37.         else if (num[i] == '1' && carry == 1)
  38.         {
  39.             ans++;
  40.             carry = 1;
  41.         }
  42.     }
  43.     if (carry == 1)ans++;
  44.     cout << ans;
  45.     return 0;
  46. }
Advertisement
Add Comment
Please, Sign In to add comment