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

sorry,刚才发错代码了

Posted by wangshicai100 at 2005-07-05 22:02:29 on Problem 1001
In Reply To:我的1001测试好多次了,总是wrong answer,帮忙看看吧 Posted by:wangshicai100 at 2005-07-05 21:52:24
#include <stdio.h>
#include <string.h>
#define N 1000
int main()
{
	char result[N+1];
	char temp[7];
	char sum[N+1],save[N+1];
	char inp[10];
	int	 num,i,j,k,flag,point,have,eh;
	while(scanf("%c",inp)!=-1)
	{
		have=0;
		gets(inp+1);
		if(inp[7]!=32)	
			num=10*(inp[7]-'0')+inp[8]-'0';	
			else	
				num=inp[8]-'0';
		
		for(i=0;i<N;i++)				
		{	
			result[i]=0;
			sum[i]=0;
			save[i]=0;
		}
		
		flag=4;
		for(i=0;i<6;i++)					
		{
			if(inp[i]=='.') 
			{
				eh=0;
				point=(5-i)*num;
				for(j=i+1;j<6;j++)
					if(inp[j]!='0') 
						eh=1;
				if(eh==0) have=1;
				continue;
			}
			save[flag]=temp[flag]=inp[i]-'0';
			flag--;
		}
	
		if(num==1)
		{
			if(have==0)
			{
				for(i=0;i<6;i++)
					printf("%c",inp[i]);
                                    printf("\n");
				continue;
			}
			i=0;
			while(inp[i]!='.')
			{printf("%c",inp[i]);i++;}
                            printf("\n");
                            continue;
		}
		

		for(k=0;k<num-1;k++)		//主算法
		{	
			for(j=0;j<N;j++)
				result[j]=0;
			for(i=0;i<5;i++)				
			{
				if(temp[i]==0) continue;
				flag=0;
				
				for(j=0;j<N;j++)
					sum[j]=0;
				for(j=0;j<N;j++)
					sum[j]=save[j];

				for(j=0;j<N;j++)			
				{
					sum[j]=temp[i]*sum[j]+flag;
					flag=sum[j]/10;
					sum[j]=sum[j]%10;
				}
				flag=0;
				for(j=0;j<N-i;j++)
				{
					result[j+i]+=sum[j]+flag;
					flag=result[j+i]/10;
					result[j+i]=result[j+i]%10;
				}
			}
			
			for(j=0;j<N;j++)
				save[j]=result[j];
		}
		flag=0;
		num=-1;
		for(i=0;i<N;i++)
		{
			if(result[i]==0) {num++;continue;}
			break;
		}
		for(i=N-1;i>num;i--)
		{
		//	if(have==1) {i=point;flag=1;}
			if(result[i]!=0) flag=1;
			if(i==point-1)
			{
				printf(".");
				flag=1;
			}
			if(flag==0) continue;
			printf("%c",result[i]+'0');
		}
		printf("\n");
		continue;
	}
	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