#include<iostream>
#include <algorithm>
using namespace std;
char * change(int n, int base)
{
char *p, *val;
if(base<2||base>36)
return NULL;
val = (char *) malloc(40);
if(!val)
return NULL;
p=val;
while( n)
{
*p= (n%base)>9? n%base-10+'a':n%base+'0';
n/=base;
++p;
}
reverse(val,p);
*p='\0';
++p;
return val;
}
int main(int argc, char* argv[])
{
char * test;
int n,base;
while(cin>>n>>base)
{
test=change(n,base);
if(test){
cout<<"Change "<<n<<" to base "<<base<<" = "<<test<<endl;
free(test);
}
else
cout<<"Wrong input."<<endl;
}
return 0;
}
posted on 2009-07-18 20:05
Bluesea 阅读(299)
评论(0) 编辑 收藏 引用 所属分类:
C/C++