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

蒟蒻改了N次终于AC,细节好多,贴个无脑代码

Posted by DAZADE8 at 2016-10-06 20:29:48 on Problem 1001 and last updated at 2016-10-06 20:29:57
#include<stdio.h>
//FILE *fin,*fout;
char s[20];
long a[201],b[201];
long k,point;
int main()
{
	long i,j,q,w,l,e,r,f=0,zero=0;
//	fin=fopen("test.in","r");
//	fout=fopen("test.out","w");
	while(scanf("%s %ld\n",s,&k)==2)
	{
	
	for(i=1;i<=200;i++)
	a[i]=0;
	q=0;
	for(i=0;i<=5;i++)
	if(s[i]=='.')point=5-i;
	else q=q*10+s[i]-'0';
	if(k==0)printf("1");
	else if(q==0)printf("0");
	else 
	{
	w=q;l=5;point=point*k;
	for(i=1;w>0;i++)
	{
		a[i]=w%10;
		w=w/10;
	}
	for(i=2;i<=k;i++)
	{
		for(j=1;j<=l;j++)
		{
			e=a[j]*q;
			r=0;
			while(e!=0)
			{
				b[j+r]=b[j+r]+e%10;
				if (b[j+r]>=10) 
				{
					b[j+r+1]++;
					b[j+r]=b[j+r]-10;
				}
				e=e/10;
				r++;
			}
		}
		f=0;
		for(j=200;f==0;j--)
		if (b[j]!=0)
		{
			f=1;
			l=j;
		}
		for(j=1;j<=l;j++)
		{
			a[j]=b[j];
			b[j]=0;
		}
	}
	zero=0;f=0;
	for(i=1;f==0;i++)
	if(a[i]!=0) f=1;
	else if (i<=point) zero++;
	if (point>l) 
	{
		printf(".");
		for(i=1;i<=point-l;i++)
		printf("0");
	}
	for(i=l;i>=1+zero;i--)
	if (i==point) printf(".%ld",a[i]);
	else printf("%ld",a[i]);
	}
	printf("\n");
	}
//	fclose(fin);
//	fclose(fout);
	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