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

Re:格式巨坑 测试n次没有错啊 差点自闭 原来发现是连续输入

Posted by xiaojiner at 2019-03-30 17:38:19 on Problem 1001
In Reply To:格式巨坑 测试n次没有错啊 差点自闭 原来发现是连续输入 Posted by:xiaojiner at 2019-03-30 17:35:49
> #include <iostream> 
> #include <string>
> using namespace std;
> string twoDataAdd(string s1,string s2)
> {
> 	string max,min;
> 	int maxLength,minLength;
> 	if(s1.length()>s2.length())
> 	{
> 		max=s1;
> 		min=s2;
> 	}
> 	else
> 	{
> 		max=s2;
> 		min=s1;
> 	}
> 	maxLength=max.length();
> 	minLength=min.length();
> 	int i,j;
> 	for(i=maxLength-1,j=minLength-1;j>=0;j--,i--)
> 	{
> 		max[i]=max[i]+min[j]-'0';
> 	}
> 	for(i=maxLength-1;i>0;i--)
> 	{
> 		if(max[i]>'9')
> 		{
> 			max[i]-=10;
> 			max[i-1]+=1;
> 		}
> 	}
> 	if(max[0]>'9')
> 	{
> 		max[0]-=10;
> 		max="1"+max;
> 	}
> 	return max;
> }
> string twoDataMultiply(string s1,string s2)
> {
> 	string max,min;
> 	if(s1.length()>s2.length())
> 	{
> 		max=s1;
> 		min=s2;
> 	}
> 	else
> 	{
> 		max=s2;
> 		min=s1;
> 	}
> 	int i,j,z;
> 	int s1Length=max.length();
> 	int s2Length=min.length();
> 	string *calculateStringArray=new string[s2Length];
> 	for(i=s2Length-1,z=0;i>=0;i--,z++)
> 	{
> 		int s2BiteToInt=(char)min[i]-'0';
> 		int carryData=0;
> 		string perString="";
> 		for(j=s1Length-1;j>=0;j--)
> 		{
> 			int s1BiteTonInt=(char)max[j]-'0';
> 			int temp=s2BiteToInt*s1BiteTonInt;
> 			int tag1=temp/10;
> 			int tag2=temp%10;
> 			int tempData=tag2+carryData;
> 			int tagCarryData=0;
> 			if(tempData>=10)
> 			{
> 				tagCarryData+=1;
> 				tempData%=10;
> 				if(tag1>0)
> 				{
> 					tagCarryData+=tag1;
> 				}
> 			}
> 			else
> 			{
> 				if(tag1>0)
> 				{
> 					tagCarryData+=tag1;
> 				}
> 			}
> 			carryData=tagCarryData;
> 			char c=tempData+'0';
> 			perString=c+perString;
> 		}
> 		if(carryData>0)
> 		{
> 			char b=carryData+'0';
> 			perString=b+perString;
> 		}
> 		for(int k=0;k<z;k++)
> 		{
> 			perString+='0';
> 		}
> 		calculateStringArray[z]=perString;
> 	}
> 	string eventuallyData=calculateStringArray[0];
> 	if(z>0)
> 	{
> 		for(int m=1;m<z;m++)
> 		{
> 			eventuallyData=twoDataAdd(eventuallyData,calculateStringArray[m]);
> 		}
> 	}
> 	return eventuallyData;
> }
> int main()
> {
> 	string templateString;//输入的数据 
> 	int n;//它的n次幂 
> 	while(cin>>templateString>>n)
> 	{
> 	
> 	int pointLacation=templateString.find('.');
> 	int templateStringLength=templateString.length();
> 	int allPoint=(templateStringLength-pointLacation-1)*n;
> 	string eventuallyData;
> 	if(pointLacation==-1)
> 	{
> 		allPoint=0;
> 	}
> 	
> 	string s1="";
> 	string s2="";
> 	int i;
> 	for(i=0;i<pointLacation;i++)
> 	{
> 		s1+=templateString[i];
> 	}
> 	
> 	for(i=pointLacation+1;i<templateStringLength;i++)
> 	{
> 		s2+=templateString[i];
> 	}
> 	string actualString=s1+s2;
> 	int actualStringLength=actualString.length();
> 	if(actualString[0]=='0')
> 	{
> 		for(i=1;i<actualStringLength;i++)
> 		{
> 			if(i!=0) break;
> 		}
> 		actualString.erase(0,i);
> 		
> 	}
> 	eventuallyData=actualString;
> 	while(n>=2)
> 	{
> 		eventuallyData=twoDataMultiply(eventuallyData,actualString);
> 		n--;
> 	}
> 	if(allPoint<eventuallyData.length()&&allPoint!=0)
> 	{
> 		eventuallyData.insert(eventuallyData.length()-allPoint,".");
> 	}
> 	else if(allPoint==eventuallyData.length())
> 	{
> 		
> 			eventuallyData.insert(0,".");
> 	}
> 	else if(allPoint>eventuallyData.length())
> 	{
> 		int replacePoint=allPoint-eventuallyData.length();
> 		string temp1=".";
> 		while(replacePoint>0)
> 		{
> 			temp1=temp1+'0';
> 			replacePoint--;
> 		}
> 		eventuallyData.insert(0,temp1);
> 	}
> 	int rightRange=eventuallyData.length();
> 	int sumLength=rightRange;
> 	if(eventuallyData.find('.')!=-1)
> 	{
> 		while(eventuallyData[rightRange-1]=='0')
> 		{
> 			rightRange--;
> 		}
> 		eventuallyData.erase(rightRange,sumLength-rightRange);
> 		if(eventuallyData[rightRange-1]=='.')
> 		{
> 			eventuallyData.erase(rightRange-1,1);
> 		}
> 	}
> 	cout<<eventuallyData<<endl;
> }
> 	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