HDU-2031 C-进制转化
题目链接:
http://acm.hdu.edu.cn/showproblem.php?pid=2031
题目分析:
利用数组存储,逆序输出即可
#include<iostream>
#include<algorithm>
using namespace std;
char res[10010];
int i;
char solve[] = {'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'};
void Reverse(int n,int m){
while(n!=0){
res[i] = solve[n%m];
n /= m;
i++;
}
}
int main(void)
{
int n,m;
while(cin>>n>>m)
{
i = 0;
if(n<0){
cout<<"-";
}
n=abs(n);
Reverse(n,m);
i--;
for(;i>=0;i--){
cout<<res[i];
}
cout<<endl;
}
}