Advertisement
gha890826

a034. 二進位制轉換

Sep 18th, 2018 (edited)
207
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.34 KB | None | 0 0
  1. #include<iostream>
  2. //dGhpcyBwcm9ncmFtIGlzIGxlYXJuaW5nIHNhbXBsZSwgZG9uJ3QgdXNlIGl0IGZvciB5b3VyIGhvbWV3b3Jr
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7.     int in;
  8.     while(cin>>in)
  9.     {
  10.         string ans;
  11.         while(in>0)
  12.         {
  13.             if(in%2!=0)
  14.             {
  15.                 ans='1'+ans;
  16.             }
  17.             else
  18.             {
  19.                 ans='0'+ans;
  20.             }
  21.             in/=2;
  22.            
  23.         }
  24.         cout<<ans<<endl;
  25.     }
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement