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

很麻烦的题目,贴出代码(G++)

Posted by seedeed at 2011-02-02 21:00:47 on Problem 1001
#include "cstdio"
#include "cstring"
char ans[100];
int main()
{
    char r[10];
	int n,bit,num,i,d,j,temp,e,len;
	bool flag;
	while(scanf("%s%d",r,&n)==2)
	{
		len=strlen(r);
		bit=0;
		flag=false;
		for(i=0;r[i];i++)
		{
			if(flag) bit++;
			if(r[i]=='.') flag=true;
		}
		bit*=n;
		num=0;
		for(i=0;i<300;i++) ans[i]=0;
		for(i=0;i<6&&r[i];i++)
			if(r[i]>='0'&&r[i]<='9') num=num*10+r[i]-'0';
		temp=num;
		for(i=0;temp;i++)
		{
			ans[i]=temp%10+'0';
			temp/=10;
		}
		for(i=1;i<n;i++)
		{
			d=0;
			for(j=0;ans[j];j++)
			{
				e=(ans[j]-'0')*num+d;
				ans[j]=e%10+'0';
				d=e/10;
			}
			while(d)
			{
				ans[j++]=d%10+'0';
				d/=10;
			}
		}
		if(n>1) len=j;
		else len=strlen(ans);
		for(i=0;i<len&&ans[i];i++)
		{
			if(ans[i]=='0'&&i<bit) continue;
			else
			{
				ans[i-1]=0;
				break;
			}
		}
		if(bit>=len)
		{
			putchar('.');
			while(bit>len)
			{
				putchar('0');
				bit--;
			}
			for(i=len-1;i>=0&&ans[i];i--) putchar(ans[i]);
			printf("\n");
		}
		else
		{
			for(i=len-1;i>=0&&ans[i];i--)
			{
				putchar(ans[i]);
				if(i==bit&&ans[i-1]) putchar('.');
			}
			printf("\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