任意进制转换

View Code
#include<stdio.h>
#include<string>
#include<stack>
using namespace std;
int main(){
int m,i,j,k;
char ch[1000],map[]="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
int t;
scanf("%d",&t);
while(t--){
__int64 n=0;
stack<int>s;
scanf("%d%d%s",&m,&k,ch);
for(i=0;i<strlen(ch);i++){//m进制转换为10 进制
if (ch[i]>64) n=n*m+ch[i]-55;
else n=n*m+ch[i]-48;
}
do{
s.push(n%k);
n/=k;
}
while (n);
while (!s.empty()){
printf("%c",map[s.top()]);
s.pop();
}
printf("\n");
}
}
posted @ 2012-02-14 20:35  Because Of You  Views(227)  Comments(0)    收藏  举报