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

总是runtime error ,贴代码,哪个前辈帮我看看啊。。。。

Posted by 330980996 at 2010-11-09 17:33:57 on Problem 1001
#include<iostream>
using namespace std;
void work(int a[10],int la,int n,int dot);
int main()
{
	freopen("in1001.txt","r",stdin);
	int n,dot,la,i,j,a[7];
	char ch[6];
	while(cin>>ch>>n)
	{
		j=6;
		dot=0;
		for(i=0;i<6;i++)
			if(ch[i]=='.') 
				dot=5-i;  //找小数点后有几位
			else 
			{
				a[j]=int(ch[i])-int('0'); //转到数组a
				j--;  
			}
		if(dot)
		{
			la=5;
			for(i=1;i<=5;i++) a[i]=a[i+1];//调整数组a
		}
		else la=6;
		//下面是把前后的0都清掉
    	while(!a[la] && la)  la--;
		while(!a[1] && la && dot)
		{
			for(j=2;j<=la;j++)
				a[j-1]=a[j];
			la--;
			dot--;
		}
		if(n==0) cout<<1<<endl;
		else
		if(la==0) cout<<0<<endl;
		else 
			work(a,la,n,dot);//开始计算 对长度为la的数组a计算n次方,小数位有dot
	}
	return 0;
}
void work(int a[7],int la,int n,int dot)
{
	int b[155]={0,1},c[155],lb=1,i,j,jw,lc,t;//b数组保存最终结果,初值是1。也就是0次方 lb为长度,初值为1
	dot=dot*n;//最终结果的小数点后位数
	while(n--)//进行n次
	{
		for(i=1;i<=155;i++) c[i]=0;//c为临时数组,清零
		for(i=1;i<=la;i++)
		{
			jw=0;//进位
			for(j=1;j<=lb;j++)//开始计算高精度惩罚,保存到c
			{
				t=(c[j+i-1]+a[i]*b[j]+jw);
				c[j+i-1]=t%10;
				jw=t/10;
			}
			if(jw) //判断有没有溢出长度
			{
				c[lb+i]=jw;
				lc=lb+i;
			}
			else lc=lb+i-1;
		}
		for(i=1;i<=lc;i++)//将每乘一次的结果都保存到b
			b[i]=c[i];
		lb=lc;
	}
	//以下为输出b
	if(dot>lb)
	{
		cout<<'.';
		for(i=dot;i>lb;i--)
			cout<<0;
		for(i=lb;i>0;i--)
			cout<<b[i];
		cout<<endl;
	}
	else
	{
		for(i=lb;i>0;i--)
			if(i==dot) cout<<'.'<<b[i];
			else cout<<b[i];
		cout<<endl;
	}
}

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