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

呜呜,dicuss里的测试数据都过了,还是wrong answer,请大虾帮帮我找找错嘛

Posted by yangchangxiu at 2007-12-06 17:01:46 on Problem 1001
#include"stdio.h"
#include"string.h"
#include"math.h"
#define M 400
#define N 100
void decimal(char *p,int *n)
{
	int i,j=0,k,t,r;
	for(i=0;p[i];i++)
		if(p[i]=='.') break;
	while(p[j]&&p[j]=='0') j++;
	if(i==strlen(p))
	{
        for(k=j;p[k];k++)
			p[k-j]=p[k];*n=0;
		p[k-j]='\0';
	}
	else
	{
		t=strlen(p)-1;r=0;
		while(t>=0&&p[t]=='0') t--;
		*n=t-i;
		for(k=j;k<=t;k++)
		   if(p[k]!='.') {p[r]=p[k];r++;}
		p[r]='\0';
	}
}
void fun(char *p,long *a1)
{
	int i,j,k,t;
	t=N-1;
	j=strlen(p);
	for(i=j-4;i>=0;i-=4)
	{
		for(k=i;k<i+4;k++)
			a1[t]=a1[t]*10+p[k]-'0';
		t--;
	}
	if(i!=-4)
	{
		for(k=0;k<i+4;k++)
			a1[t]=a1[t]*10+p[k]-'0';
		t--;
	}
}
int main()
{
	char s1[M],s2[M],s3[M];
	long a1[N],a2[N],a3[N],m,n;
	int i,j,k,t,j1,j2,n1,n2,r,h,h1,h2;
	while(scanf("%s%d",s1,&h)!=EOF)
	{	
		for(i=0;s1[i];i++)
			s2[i]=s1[i];
		s2[i]='\0';
		decimal(s1,&n1);
		i=0;while(s1[i]=='0') i++;
		if(s1[i]=='\0') { printf("0\n");continue;}
		h2=h*n1;
	for(h1=1;h1<h;h1++)	
	{	
		for(i=0;i<N;i++)
			a1[i]=a2[i]=a3[i]=0;
		decimal(s1,&n1);
		fun(s1,&a1[0]);
		decimal(s2,&n2);
		fun(s2,&a2[0]);
		j1=j2=0;
		while(j1<N&&a1[j1]==0) j1++;
		while(j2<N&&a2[j2]==0) j2++;
	    for(i=N-1;i>=j1;i--)
		{
			for(j=N-1;j>=j2;j--)
			{
				k=j+i-N+1;
				n=a1[i]*a2[j];
				while(n!=0)
				{
					a3[k]=a3[k]+n%10000;
					n=n/10000;
					m=a3[k];k--;t=k;
					while(m>=10000)
					{
						a3[t+1]=m%10000;
						a3[t]=a3[t]+m/10000;
						m=a3[t];t--;
					}
				}
			}
		}
		k=0;
		for(i=t+1;i<N;i++)
		{
			m=a3[i];j=0;
		    while(m) {j++;m/=10;}
		   if(i==t+1) 
			while(j)				
			{  
				s3[k]=a3[i]/(int)pow((double)10,(double)(j-1))+'0';a3[i]%=(int)pow((double)10,(double)(j-1));k++;j--;
			}
			else 
			{ 
				for(r=0;r<4-j;r++)
				    s3[k++]='0';
				while(j)
				{ s3[k]=a3[i]/(int)pow((double)10,(double)(j-1))+'0';;a3[i]%=(int)pow((double)10,(double)(j-1));k++;j--;}
			}
		}
		s3[k]='\0';
		for(i=0;s3[i];i++)
			s2[i]=s3[i];
		s2[i]='\0';
	}
	n=h2;
    if(h==0) printf("0\n");
    else 
	{
		if(h==1) { fun(s1,&a3[0]);for(i=0;s1[i];i++) s3[i]=s1[i];s3[i]='\0';k=strlen(s1);}
		if(n>=k)
		{
			printf(".");
			for(i=k;i<n;i++)
				printf("0");
		    printf("%s\n",s3);
		}
		else if(n!=0) 
		{
			for(i=0;i<k-n;i++)
				printf("%c",s3[i]);
			printf(".");
			for(i=k-n;i<k;i++)
				printf("%c",s3[i]);
			printf("\n");
		}
		else printf("%s\n",s3);
	}
	}
	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