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

大家讨论的BT数据我都通过了,但还是WA,大家看看是哪里有问题呀.

Posted by Bupt_Pig at 2006-03-01 16:04:37 on Problem 1001
/*
**1001pkuacm.
*/

#include <stdio.h>
#include <stdlib.h>
#include <iostream.h>

main()
{
	char s[7];
	int a,i,m,n,b[1001]={0},temp,q,p;

	while(cin>>s>>n)
	{

	for(i=0;i<=1000;i++)
		b[i]=0;
	for(i=0;s[i]!='.'&&s[i];i++)
		;
	if(i==6)
		m=0;
	else
	{
		m=5-i;
		while(s[i])
		{
			s[i]=s[++i];
		}
	}	
	a=atoi(s);           //确定输入数中的小数位.并转化为整数型. 
	
	temp=a;
	i=0;
	while(temp>0)
	{
		b[1000-i]=temp%10;
		temp=temp/10;
		i++;
	}
	temp=n;	
	while(temp!=1)               //计算. 
	{
		for(i=1000;i>0;i--)
		{
			b[i]=b[i]*a;
		}
		for(i=1000;i>0;i--)
		{
			if(b[i]/10!=0)
			{
				b[i-1]=b[i-1]+b[i]/10;
				b[i]=b[i]%10;
			}
		}
		temp--;
	}
	
	
	m=m*n;             //确定结果里的小数部分.下面为输出. 
	for(p=1;p<=1000&&b[p]==0;p++)
		;
	if(p>1000)
	{
		printf("0\n");
		return 1;
	}
	for(q=1000;q>=1&&b[q]==0;q--)
		;
	if(1000-p+1<=m)
	{
		printf(".");
		for(i=1000-m+1;i<=q;i++)
			printf("%d",b[i]);
		printf("\n");
	}
	else
	{
		if(1000-q>=m)
		{
			for(i=p;i<=1000-m;i++)
				printf("%d",b[i]);
			printf("\n");
		}
		else
		{
			for(i=p;i<=1000-m;i++)
				printf("%d",b[i]);
			printf(".");
			for(i=1000-m+1;i<=q;i++)
				printf("%d",b[i]);
			printf("\n");
		}
	}
	
	}//while(cin>>);
	


}
	


	

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