ハワイ好きの王様
2008.09.13 22:10 パソコン甲子園 2008
解説
基数変換の問題です。
10進数 n を B 進数に変換するには、
n を B で割った余りを並べていきます。
サンプルプログラム
001 #include<iostream>
002 using namespace std;
003 #define BASE 4
004
005 void parse( int x ){
006 if ( x / BASE ) parse( x / BASE );
007 cout << x % BASE;
008 }
009
010 int main(){
011 int n;
012 while( cin >> n && n >= 0){
013 parse(n);
014 cout << endl;
015 }
016 return 0;
017 }
スポンサーサイト
| コメント(0) | トラックバック(0) | ↑ページトップ |