关于进制转换的问题,求进,在线等大牛
编写一个程序,输入三个整数n A B,表示把A进制的n,转换为B进制,并输出。
样例:
输入 输出
11 8 10 9
129 10 2 10000001
22 3 6 12
假定输入的A和B都在2-10这个范围,超出范围的不用去处理,输入的n保证在int范围内。
如题,求代码!!!!
[解决办法]
#include <iostream>#include <cmath>#include <string>using namespace std;void func(string n,int A,int B){ int real=0; int i; for (i=0;i<n.length();i++) { real=real*A+int(n[i]-'0'); } string taget; while (real>0) { taget=char('0'+real%B)+taget; real/=B; } cout<<taget<<endl;}int main(){ string number; int A,int B; while (cin>>number>>A>>B) { func(number,A,B); }}
[解决办法]