再把每次得到的餘數存進陣列中,
再輸出即是答案。
[C++](2ms, 700KB)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<iostream> | |
using namespace std; | |
int main() | |
{ | |
int n; | |
while( cin >> n ) | |
{ | |
int output[1000]; | |
int outputrange = 0; | |
while( n ) | |
{ | |
output[outputrange++] = n % 2; | |
n /= 2; | |
} | |
if( outputrange ) | |
{ | |
for( int i = outputrange-1 ; i >= 0 ; i-- ) | |
cout << output[i]; | |
cout << endl; | |
} | |
else | |
cout << 0 << endl; | |
} | |
return 0; | |
} |
0 意見:
張貼留言