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

呜呜……好郁闷啊,做了一天了,到底那里错了?那位大侠给看看啊,谢谢!

Posted by myi_i at 2004-10-23 15:28:58 on Problem 1001
#include"stdio.h"
#include"string.h"
#define M 200
main()
{
	char *a,*b,*c,*temp;
	char one[M],two[M],three[M],input[6],s[6];
	int i,j,k,n,point,alen,blen,clen,sum,mul,carry=0,flag;

	while (scanf("%s %d",s,&n)!=EOF)
	{

		a=one;
		b=two;
		c=three;
		memset(one,0,M);
		memset(two,0,M);
		memset(three,0,M);

		for(i=5;i>=0;i--)
		{input[i]=s[5-i];}

		point=-1;
		alen=6;
		for(i=0,j=0;i<6;i++)
		{
			if(input[i]!='.')
			{a[j]=input[i];j++;}
			else
			{point=n*i;alen--;}
		}
		for(i=0;i<alen;i++)
		{a[i]-=48;}
		memcpy(two,one,6);
		blen=alen;


		//开始计算
		for(k=0;k<n-1;k++)
		{
			clen=alen+blen-1;
			carry=0;

			//字符串乘法c=a×b
			for(i=0;i<clen;i++)
			{
				sum=carry;
				carry=0;
		
				for(j=0;j<blen;j++)
				{
					if(i-j>=0 && i-j<alen)
					{
						mul=a[i-j]*b[j];
						carry+=mul/10;
						sum+=mul%10;
					}
				}
				carry+=sum/10;
				c[i]=(char)sum%10;
			}
			if(carry)
			{clen++;c[clen-1]=(char)carry;}
			//字符串乘法结束

			temp=a;a=c;c=temp;
			alen=clen;
		}

		//输出
		flag=0;
		for(i=0;i<blen;i++)
			if(b[i]!=0)
				flag=1;

		if(n==0 && flag==1)
			printf("1");
		else

		if(point<0)
		{
			for(i=alen-1;i>=0;i--)
			{printf("%c",a[i]+48);}
		}
		else
		{
			k=0;
			while(a[k]==0 && k<alen)
				k++;

			j=alen-1;
			while(a[j]==0 && j>=0)
				j--;

			if(j<point)
			{
				if(k!=alen)
				{
					printf(".");
					for(i=point-1;i>=k;i--)
					{printf("%c",a[i]+48);}
				}
				else
					printf("%c",48);
			}
			
			else if(j!=point)
			{
				if(k<point)
				{
					for(i=j;i>=k;i--)
					{
						printf("%c",a[i]+48);
						if(i==point)
							printf(".");
					}
				}
				else
				{
					for(i=j;i>=point;i--)
					{printf("%c",a[i]+48);}
				}
			}
			else
			{
				for(i=j;i>=k;i--)
					{printf("%c",a[i]+48);}
			}
		}
		printf("\n");

	}
}

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