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

结果如果是0,输出0.000,与输出0.都对,本人测试过了,数组100足够用了

Posted by 420788708 at 2010-08-19 20:33:55 on Problem 1131 and last updated at 2010-08-19 20:51:22
#include<iostream>
#include<string>
将8进制化为2进制,因为
0.1111[2]=0.5+0.25+0.125+0.625+……,
算式如下:
 5
+25
+125
+ 625
……
0.1001[2]=0.5+0.625
 5
+(此处只算不加)
+(同上)
+ 625
————
.5625
2进制要是1就加,是0就不用加
就是结果每次都错位
using namespace std;
int a[8][3]={0,0,0,0,0,1,0,1,0,0,1,1,1,0,0,1,0,1,1,1,0,1,1,1};
int main()
{
	int b[100],ji[100][100],res[100],tem[100];
	char c[100];
	int leng,j,i,k,m,max,t;
	memset(ji,0,sizeof(ji));
	//freopen("2.txt","r",stdin);
	while(scanf("%s",c)!=EOF)
	{
		memset(res,0,sizeof(res));
		memset(tem,0,sizeof(tem));
		i=0;
		while(c[i++]!='.');
		leng=(strlen(c)-i)*3;
		for(j=0;j<leng;i++)//转换为2进制。
		{
			t=c[i]-'0';
			b[j++]=a[t][0];
			b[j++]=a[t][1];
			b[j++]=a[t][2];
		}
		ji[0][0]=1;
		max=0;
		for(i=0;i<j;i++)
		{
			t=i+1;
			if(max>=i)
			{
				for(k=0;k<=i;k++)
				{
					ji[t][k]=ji[i][k]*5;
				}
				for(k=0;k<=i;k++)
				{
					if(ji[t][k]>9)
					{
						ji[t][k+1]+=ji[t][k]/10;
						ji[t][k]=ji[t][k]%10;
					}
				}
				max++;
			}
			if(b[i])
			{
				tem[0]=ji[t][0];
				if(i)
					k=1;
				else
					k=0;
				for(m=0;m<=i;m++,k++)
				{
					tem[k]=ji[t][k]+res[m];
					if(tem[k]>9)
					{
						res[k]+=tem[k]/10;
						tem[k]=tem[k]%10;
					}
				}
				for(k=0;k<=i+1;k++)
				{
					res[k]=tem[k];
				}
			}
			else
			{
				for(k=i+2;k>0;k--)
					res[k]=res[k-1];
				res[0]=0;
			}
		}
		m=i;
		printf("%s [%d] = ",c,8);
		j=0;
		while(!res[j++]&&j<=i);j=j-1;
	//	if(j==i)
	//		j=j-1;
		if(leng>=i+1)
		{
			printf("0.");
			while(leng>i+1)
			{printf("0");i++;}
			for(;m>=j;m--)
			{
				printf("%d",res[m]);
			}
		}
		else
		{
			while(m>=leng)
				printf("%d",res[m--]);
			printf(".");
			if(res[j-1]=='.')
				printf("0");
			while(m>=j)
				printf("%d",res[m--]);
		}
		printf(" [%d] \n",10);
	}
	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