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

谁能帮我一下 老是错 几乎每种情况都想到了

Posted by 00448083 at 2005-04-02 22:08:14 on Problem 1001
#include <iostream.h>
#include<string.h>
#define ANUM 100
void main()
{
	int resdot, basdot, baslen, reslen, templen, op2len;
	char string[7];
	int xunhuan;
	while (cin>>string>>xunhuan) 
	{				
		/*           初始化             */
		resdot=basdot=baslen=reslen=templen=op2len=0;
		short base[ANUM]={0}, result[ANUM]={0}, op2[ANUM]={1};
		int i, j;
		if(xunhuan==0)
			result[0]=1;
		for(j=strlen(string)-1, i=0; i<ANUM&&j>=0; i++,j--) 
		{			
			if(string[j]=='.')
			{
				basdot=i;
				i--;
			}
			else
			{
				base[i]=string[j]-'0';
			}
		}
		baslen=5;
		reslen=0;
		op2len=1;
		/*   初始化中有 base result op2   */
		for(i=0; i<xunhuan; i++)//作乘法
		{
			int m, n;
			int carry=0;
			for(m=0; m<reslen; m++)
				result[m]=0;
			for(m=0; m<baslen; m++)
			{	
				carry=0;//进数赋零
				for(n=0; n<op2len; n++)
				{
					result[m+n]+=base[m]*op2[n]+carry;//计算
					carry=result[m+n]/10;
					result[m+n]%=10;			
				}
				while(carry>0)
				{
					result[m+n++]=carry%10;
					carry/=10;
				}			
				reslen=m+n;
			}
			for(m=0; m<reslen; m++)
			{
				op2[m]=result[m];
				op2len=reslen;
			}
		}
		resdot=basdot*xunhuan;//小数点
		for(i=0; i<reslen&&result[i]==0; i++) ;
		j=i;
		int is=0;
		for(i=reslen-1; i>j; i--)
		{
			if(result[i]>0||is>0)
				cout<<result[i];
			if(resdot==i)//输出小数点
			{
				cout<<".";
				is++;
			}
		}
		cout<<result[j]<<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