首页 > 其他 > 详细

进制转换器

时间:2018-03-08 22:44:00      阅读:228      评论:0      收藏:0      [点我收藏+]
 1 /*
 2 进制转换器 
 3 P进制数x转为Q进制数z
 4 过程模拟,先转十进制再转目标进制 
 5 */
 6 #include<cstdio> 
 7 #include<algorithm>
 8 #include<stack>
 9 using namespace std;
10 int main(){
11     int p,q;
12     int x,y=0,z;
13     int a=1; 
14     stack<int> sta;
15     scanf("%d%d%d",&p,&q,&x);
16     while(x!=0) {
17         y = y + (x%10)*a;
18         x = x/10;
19         a = a * p;
20     }
21     do{
22         z = y % q;
23         sta.push(z);
24         y = y / q;
25     }while(y!=0);
26     while(!sta.empty()){
27         printf("%d",sta.top());
28         sta.pop();
29     }
30     return 0;
31 } 

 

进制转换器

原文:https://www.cnblogs.com/javier2018/p/8531099.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!