题目链接:
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;
}
}
逆序输出进制转换
本文介绍了一种使用数组存储并逆序输出任意进制数的方法。通过C++实现,适用于ACM竞赛中的特定问题。具体步骤包括读取输入的十进制数和目标进制数,然后进行转换。
253

被折叠的 条评论
为什么被折叠?



