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

高精度写的我郁闷,虽然ac了,但是感觉不爽,高手帮忙看看我哪里写的不好:

Posted by zhb_msqx at 2007-09-09 22:50:56 on Problem 3331
char * mult(const char *sl,const char *sr){
//	cout<<sl<<" "<<sr<<endl;
	int len1=strlen(sl);
	int len2=strlen(sr);
	int i,j,k;

	int ms[INF];
	memset(ms,0,INF);

	for(i=len1-1;i>=0;i--){
		for(j=len2-1;j>=0;j--){
			int cp1=sl[i]-'0';
			int cp2=sr[j]-'0';
		//	cout<<cp1<<cp2<<endl;
			int curpos=len1-1-i+len2-1-j;
		//	cout<<curpos<<endl;

			ms[curpos]+=cp1*cp2;
		//	cout<<ms[curpos]<<endl;
		}
	}
	for(i=0;i<len1+len2+10;i++){
		if(ms[i]>=10){
			int up=ms[i]/10;
			ms[i]=ms[i]%10;
			ms[i+1]+=up;
		}
	}
/*	for(i=len1+len2+5;i>=0;i--){
		cout<<ms[i]<<" ";
	}
	cout<<endl;
*/	

	char *ans=new char[INF];
	int an=0;
	bool first=false;
	for(i=len1+len2+5;i>=0;i--){
		if(!first){
			if(ms[i]==0)continue;
			ans[an++]='0'+ms[i];
			first=true;
		}else{
			ans[an++]='0'+ms[i];
		}
	}
	ans[an]='\0';
//	cout<<strlen(ans)<<endl;
	return ans;

}

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