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 ljhlogic at 2016-09-04 15:57:27 on Problem 1001
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<cmath>
#include<cstdio>
#include<string>
#include<sstream>
using namespace std;
int number1[200][200];

int main()
{
string c;
int a=0;
int b;
while(cin>>c>>b)
{
	a=0;
    int s=0;
	int temp;
int leng=c.length();

for(int i=0;i<leng;i++)
{
	if(c[i]=='.')
	{
		for(int j=i+1;j<leng;j++)
		{
			s++;
		}
		break;
	}
}
int u=1;

for(int i=leng-1;i>=0;i--)
{
	if(c[i]!='.')
	{
	a+=(c[i]-'0')*u;
	u*=10;
    }
}

temp=a;

double q=(double)a/pow(10.0,(double)s);
	if(a==0)
	{
		if(b!=0)
		{
		cout<<0<<endl;
		continue;
		}
		else
		{
		cout<<1<<endl;
		continue;
		}
	}
	if(b==0)
	{
		cout<<1<<endl;
		continue;
	}
	memset(number1,0,sizeof(number1));

	int temp2=temp;

	int number2[200];
	memset(number2,0,sizeof(number2));
	int flag=0;
	while(temp2>0)
	{
		int r=temp2%10;
		number2[199-(flag)]=r;
		flag++;
		temp2/=10;
	}

	for(int i=0;i<200;i++)
	{
		number1[199][i]=number2[i];
		
	}
	int number3[200];
	memset(number3,0,sizeof(number3));
if(b==1)
{
		for(int i=0;i<200;i++)
	{
		number3[i]=number2[i];
		
	}
}
else
for(int k=1;k<b;k++)
{

int number4[200];
for(int i=0;i<200;i++)
{
	number4[i]=number1[199][i];
}
	int flag3=0;
	for(int i=199;i>=0;i--)
	{
		for(int j=199;j>=0;j--)
		{
		number1[i][j-flag3]=number4[j]*number2[i];
		
		}
		flag3++;
		if(flag3==10)break;
	}

	memset(number3,0,sizeof(number3));
for(int i=199;i>=0;i--)
{
	for(int j=199;j>=0;j--)
	{
		number3[i]+=number1[j][i];
	}
}
memset(number1,0,sizeof(number1));
	for(int i=199;i>=0;i--)
	{
		int temp=number3[i];
		number3[i]=temp%10;
		number3[i-1]+=temp/10;
	}
		for(int i=199;i>=0;i--)
	{
	number1[199][i]=number3[i];
	}

}

	if((int)q==0)
	{
		cout<<".";
		int flag=0;
	
			
				int w=200;
				for(int j=199;j>=0;j--)
				{
					if(number3[j]!=0)
					{
						w=j;
						break;
					}
				}
				for(int j=200-s*b;j<=w;j++)
				{
					cout<<number3[j];
				}
				cout<<endl;
				
			
		
	}
	else
	{
		int kk=200;
		for(int i=200;i>200-s*b;i--)
		{
			if(number3[i]!=0)
			{
				kk=i;
				break;
			}
		}
		for(int i=0;i<200;i++)
		{
			if(number3[i]!=0)
			{
				for(int j=i;j<200;j++)
				{
					if(j==200-s*b&&kk!=200)
					{
						
						cout<<'.';
						cout<<number3[j];
					}
					if(j<200-s*b||(j>200-s*b&&kk!=200&&j<=kk))	
					cout<<number3[j];
				
				}
				cout<<endl;
				break;
			}
		}
	}
}
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