Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

高精度多进制之间的转换,曾经拜读过maigo的代码,非常精简的思想及实现,见内。

Posted by tzkq at 2010-07-19 22:16:44 on Problem 1220 and last updated at 2010-07-19 22:28:11
int i,l,k,a,b,T,t[555],A[555];
char s[555],d[555];
main(){

	for(scanf("%d",&T);T--;){
		scanf("%d%d%s",&a,&b,s);

		for(k=i=strlen(s);0<i--;)t[k-1-i]=s[i]-(s[i]<58?48:s[i]<97?55:61);

		for(l=0;k;){
			for(i=k;1<i--;){
				t[i-1]+=t[i]%b*a;
				t[i]/=b;
			}
			A[l++]=t[0]%b;
			t[0]/=b;
			for(;0<k&&!t[k-1];k--);
		}

		for(d[l]=i=0;i<l;i++)d[l-1-i]=A[i]+(A[i]<10?48:A[i]<36?55:61);

		printf("%d %s\n%d %s\n\n",a,s,b,d);
	}

}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator