现在的位置: 首页 > 综合 > 正文

HDU 2031 进制转化

2018年04月29日 ⁄ 综合 ⁄ 共 253字 ⁄ 字号 评论关闭
# include<cstdio>
# include<iostream>

using namespace std;

int m;
void f( int x )
{
    if ( x == 0 )return;
        f( x/m );
            char a;
                a = ( x%m >9 ? x%m-10+'A':x%m+'0');
                    cout<<a;
}

int main(void)
{
    int n;
    while ( cin>>n>>m )
    {
        if ( n==0 )
            cout<<"0"<<endl;
            if ( n > 0 )
                    f(n);
                if ( n < 0 )
                        {
                            cout<<"-";
                            f(-n);
                        }

                    cout<<endl;
    }


    return 0;
}

抱歉!评论已关闭.