#include <stdio.h>
#include <string.h>
char * jiu2shijiu(char * shijiu , char * jiu)
{
int d , i , k , m ;
char b[66] , s[19] ;
for(k = 0 ; k < 10 ; k ++) s[k] = '0' + k ;
for(k = 0 ; k < 9 ; k ++) s[10 + k] = 'a' + k ;
for(m = strlen(jiu) , d = 0 , i = 0 ; i < m ; i ++) d = d * 9 + jiu[i] - '0' ;
for(m = 0 ; d ; d /= 19 , m ++) b[m] = s[d % 19] ;
for(k = 0 ; k < m ; k ++) shijiu[k] = b[m - 1 - k] ;
shijiu[m] = '\0' ;
return shijiu ;
}
char * shijiu2jiu(char * jiu , char * shijiu)
{
int d , i , k , m ;
char b[66] ;
for(m = strlen(shijiu) , d = 0 , i = 0 ; i < m ; i ++) {
if(shijiu[i] > '9') d = d * 19 + shijiu[i] - 'a' + 10 ;
else d = d * 19 + shijiu[i] - '0' ;
}
for(m = 0 ; d ; d /= 9 , m ++) b[m] = '0' + d % 9 ;
for(k = 0 ; k < m ; k ++) jiu[k] = b[m - 1 - k] ;
jiu[m] = '\0' ;
return jiu ;
}
main(void)
{
char jiu[66] , shijiu[66] ;
strcpy(jiu , "88888888") ;
jiu2shijiu(shijiu , jiu) ;
printf("jiu = %s\tshijiu = %s\n" , jiu , shijiu) ;
shijiu2jiu(jiu , shijiu) ;
printf("jiu = %s\tshijiu = %s\n" , jiu , shijiu) ;
}
编译、运行实况:C:\Bin>g++ -o jiu jiu.c
C:\Bin>jiu
jiu = 88888888 shijiu = h75hig
jiu = 88888888 shijiu = h75hig
C:\Bin>
|