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 }