rengetsu

HackerRank_UtopiaTree

Jul 3rd, 2018
46
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.38 KB | None | 0 0
  1. //Utopian Tree
  2. #include <iostream>
  3. using namespace std;
  4. int main()
  5. {
  6.     int n, t[100] , dis=1, q=1;
  7.     cin >> n;
  8.     for(int i=0;i<n;i++)
  9.     {
  10.         cin >> t[i];
  11.         for(int y=0;y<t[i];y++)
  12.         {
  13.             if(q==1){q=0;dis=dis*2;}
  14.             else if(q==0){q=1;dis++;}
  15.         }
  16.         cout<<dis<<endl;
  17.         dis=1;
  18.         q=1;
  19.     }
  20.     return 0;
  21. }
Add Comment
Please, Sign In to add comment