Thrashans

Potencias de 2

Aug 27th, 2016
41
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.49 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. bool esPotenciaDe2(string &s)
  6. {
  7.     int ocurrencias = 0;
  8.     for(int i = 0; i < s.length() && ocurrencias <= 1; ++i)
  9.         if(s[i] == '1')
  10.             ++ocurrencias;
  11.     return ocurrencias == 1;
  12. }
  13.  
  14. int main() {
  15.     int t;
  16.     cin >> t;
  17.     while(t--)
  18.     {
  19.         string s;
  20.         cin >> s;
  21.         if(esPotenciaDe2(s))
  22.             cout << "SI" << endl;
  23.         else
  24.             cout << "NO" << endl;
  25.     }
  26.     return 0;
  27. }
Add Comment
Please, Sign In to add comment