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 scuwf at 2012-02-11 20:07:25 on Problem 1131
#include<stdio.h>
#include<string.h>
#include<memory.h>
#define MAX 1000 //1000大了,开20就能AC了
char str[MAX];
int res[3*MAX],cop[3*MAX],cop2[3*MAX];
int main()
{
	int len,pos,i,j,temp,pre,s;
	while(scanf("%s",str)!=EOF)
	{
		len=strlen(str);
		memset(res,0,sizeof(res));
		memset(cop,0,sizeof(cop));
		cop[0]=1;
		pos=0;
		for(i=2;i<len;i++)
		{
			j=s=0;
			while(j<=pos || s!=0)
			{
				s=s*10+cop[j];
				cop[j]=s/8;
				s%=8;
				j++;
			}
			pos=j-1;
			temp=str[i]-48;
			for(j=0;j<=pos;j++) cop2[j]=cop[j]*temp;
			for(j=pos;j>=0;j--)
			{
				pre=cop2[j]/10;
				cop2[j]%=10;
				if(pre>0) cop2[j-1]+=pre;
			}
			for(j=0;j<=pos;j++) res[j]+=cop2[j];
			for(j=pos;j>=0;j--)
			{
				pre=res[j]/10;
				res[j]%=10;
				if(pre>0) res[j-1]+=pre;
			}
		}
		printf("%s [8] = 0.",str);
		for(i=1;i<=pos;i++) printf("%d",res[i]);
		printf(" [10]\n");
	}
	return 0;
}

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