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:为什么 总是显示出错呢?我运行的结果好像没错啊

Posted by 200930635154 at 2010-03-30 17:45:43 on Problem 1001
In Reply To:为什么我的程序结果总是显示出错呢?我运行的结果好像没错啊 Posted by:710817320 at 2010-03-29 08:11:25
> #include <iostream>
> #include <string>
> using namespace std;
> 
> int length_a;
> int length_b;
> int length_c=0;
> int length_p=0;
> char * MultiNum(char * a,char * b);
> void ExpNum(char *a,int n);
> 
> char * MultiNum(char * a,char * b)
> {
> 	
>    char s1[1000];
>    
>    int i,j,k=0;
>    int flag=0;
>    char c;
>    int length_pa;//保存a的小数点的位数
> 
>    length_a=strlen(a);
>    length_b=strlen(b);
>   
>    for(i=0;i<1000;i++)
>    {
> 	   s1[i]='0';
>    }
>    
> 
>    for (i=0;i<length_a;i++)
>    {
> 	   if(a[i]=='.')
> 	   {
> 		  length_a=length_a-1;
> 		  length_p=length_a-i;
> 		  length_pa=length_p;
> 		  while(i<length_a)
> 		  {
> 			  a[i]=a[i+1];
> 			  i++;
> 		  }
>          a[i]='\0';
> 	   }
> 	   
>    }
>    
>    
>    for (i=0;i<length_b;i++)
>    {
> 	   if(b[i]=='.')
> 	   {
> 		  length_b=length_b-1;
> 		  length_p=length_b-i+length_pa;
> 		  while(i<length_b)
> 		  {
> 			  b[i]=b[i+1];
> 			  i++;
> 		  }
> 		  b[i]='\0';
> 	   }
> 	   
>    }
>    
> 
>    for (i=0;i<length_a;i++)
>    {
> 	   
> 	   k=i;
> 	   flag=0;
> 	   for (j=0;j<length_b;j++)
> 	   {
>           c=(a[length_a-i-1]-48)*(b[length_b-j-1]-48)+flag+s1[i+j]-48;
> 		  if (c>=0&&c<10)
> 		  {
> 			  s1[k++]=c+48;
> 			  flag=0;
> 		  }
> 		  if (c>=10)
> 		  {    
> 			  flag=c/10;
> 			  c=c%10;
>               s1[k++]=c+48;
> 			  
> 		  }
> 	   }
> 
> 	   if(flag>0)
> 		 s1[k++]=flag+48;
>    }
>    
>    s1[k]='\0';
>    length_c=k;
>     
>    char *s2=new char[length_c+1];
>    if(length_p!=0)//计算结束后,加上小数点
>    {
> 	     for(i=0;i<length_c-length_p;i++)
> 		 {
>             s1[length_c-i]=s1[length_c-i-1];
> 		 }
>          s1[length_p]='.';
>   
>          for(i=0;i<=length_c;i++)
> 		 {
> 	       s2[i]=s1[length_c-i];
> 		 }
> 
> 		 
>    }
> 
>    else 
> 	   for(i=0;i<length_c;i++)
> 	   {
> 		   s2[i]=s1[length_c-i-1];
> 	   }
>    
>     s2[i]='\0';
>   
>    
>    if(length_pa!=0)//还原数组a的值
>    {
> 	   for(i=0;i<length_pa;i++)
> 	   {
> 		   a[length_a-i]=a[length_a-i-1];
> 	   }
> 	   a[length_a-length_pa]='.';
>    }
>    
>    return s2;
> }
> 
> 
> void ExpNum(char *a,int n)
> {  
>    int  i=0 ; 
>    char *c=new char[10000];
>    c[0]='1';
>    c[1]=0;
>    if (n>0)
>    {   
> 	   for (int i=0;i<n;i++)
> 	   {
> 		  c= MultiNum(a,c);
> 	   }
> 	   
>    }
>    if(c[0]=='0')
>    {
> 	   for(i=0;i<length_c;i++)
> 		   c[i]=c[i+1];
> 	   c[i]='\0';
>    }
> 
>    if(c[length_c]=='0')
>    {
> 	   i=length_c;
>        while((i>length_c-length_p)&&(c[i]=='0'))
> 	   {   
> 		   c[i]='\0';
> 		   i--;
> 	   }
>    }
> 
>    cout<<endl<<c<<endl;
> 
> }
> 
> 
> int main()
> {
> 	
>     int n;
> 	int i=0;
> 	char a[6][1000];
>     while(i<6)
> 	{
> 	 cin>>a[i];
>    
>      cin>>n;
>      ExpNum(a[i],n);
> 	 i++;
> 	}
> 
> 	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