本站遷移

因為我最近租用了網路空間以及網域,
故本站已遷移至新網站~
這邊的資訊已經正在進行搬移的工作~
希望各位可以到新網站去逛XD

New Website:
http://knightzone.org/

搜尋此網誌

2011年2月26日 星期六

[Zerojudge]a034: 二進位制轉換

利用while一直除2餘2,
再把每次得到的餘數存進陣列中,
再輸出即是答案。

[C++](2ms, 700KB)
#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 意見:

張貼留言