Advertisement
Josif_tepe

Untitled

Dec 23rd, 2022
859
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.39 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <set>
  4. #include <cstring>
  5. using namespace std;
  6.  
  7. int main() {
  8.     string s;
  9.     cin >> s;
  10.    
  11.     int power_of_two = 1;
  12.     int number = 0;
  13.     for(int i = s.size() - 1; i >= 0; i--) {
  14.         if(s[i] == '1') {
  15.             number += power_of_two;
  16.         }
  17.         power_of_two *= 2;
  18.     }
  19.     cout << number << endl;
  20.     return 0;
  21. }
  22.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement