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

为什么一直说我Answer Wrong 呢?(1001题)结果都对的啊。。。

Posted by jadeback at 2008-09-21 14:32:15
#include <string>
#include <iostream>
#include <vector>
using namespace std;
void chen(string chenshu ,string beichenshu,string &rs)
{
   int j=0;
  int csize=chenshu.size();
  int bsize=beichenshu.size();
  int total=csize+bsize;
  int *a=new int[csize];
  int *b=new int[bsize];
  int *res=new int[total];
  for(int i=0;i!=total;i++)
  {
    res[i]=0;
  }
  for(unsigned int i=0;i!=chenshu.size();i++)
  {  
     if(isdigit(chenshu[i]))
	 {
	   a[j]=chenshu[i]-48;
	   j++;
	 }
  }
  j=0;
  for(unsigned int i=0;i!=beichenshu.size();i++)
  {  
     if(isdigit(beichenshu[i]))
	 {
	   b[j]=beichenshu[i]-48;
	   j++;
	 }
  }
  for(int bpos=bsize-1;bpos>=0;bpos--)
  {   
	int respos=total-(bsize-bpos-1);
    for(int apos=csize-1;apos>=0;apos--)
	  {   
		  int jinwei=(a[apos]*b[bpos])/10;
		  int benwei=(a[apos]*b[bpos])%10;
		  res[respos-(csize-apos)]=benwei+res[respos-(csize-apos)];
		  res[respos-(csize-apos)-1]=jinwei+res[respos-(csize-apos)-1];
		  
	  }
  
  }
  for(int i=total-1;i>0;i--)
  {
	int tmp;
	tmp=res[i]/10;
    if(tmp>0)
	{
	 res[i-1]=res[i-1]+tmp;
	 res[i]=res[i]%10;
	}
  }
/////////////////////////
    rs.clear();
    char tran[2];
    for(int m=0;m!=total;m++)
	{
	  sprintf(tran,"%d",res[m]);
	  rs=rs+tran;
	}
//////////////////////////////
	while(rs.find_first_of("0")==0)
	{
	   rs.erase(0,1);
	}
}


void result(string &base,int pw,string &res)
{
 unsigned int pos=base.find('.');
  if(pos!=string::npos)
  {
	base.erase(pos,1);
	res=base;
	for(int i=0;i<pw-1;i++)
   {
    chen(res,base,res);
   }
	int ipos=res.size()-((5-pos)*pw);
	
	if(ipos<0)
    { 
	  int num=0-ipos;	
	  res.insert(0,num,'0');
	  res.insert(0,1,'.');
	  
	}
    else	
	{
		res.insert(ipos,1,'.');
	}
	while(res.find_last_of("0")==(res.size()-1))
	{
	   res.erase((res.size()-1),1);
	}
  }
  else
  {
   res=base;
	for(int i=0;i<pw-1;i++)
   {
    chen(res,base,res);
   }
  }
}
int main()
{
string base;
int pw;
int num=0;
string res;
vector<string> show;
while(cin>>base>>pw)
{
  result(base,pw,res);
  cout<<res<<endl;
  res.clear();
  cin.clear();
}


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