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

1001OLE

Posted by ZaakDov at 2008-12-10 12:15:13 on Problem 1001
#include <stdio.h>

#include <string.h>

int calc(int [],int,int []);
void _print(int [],int,int);
int main(){
  char a[6];
 
  int n,i,t,j,b[125]={0},c[5],s,len; 
  while(1){
    for(i=0;i<=124;i++)
      b[i]=0;
    scanf("%s",a);
    scanf("%d",&n);
    len=strlen(a);
 
    j=5;
    t=-1;
    for(i=len-1;i>=0;i--){
      if(a[i]=='.')
        t=6-len+i;
      a[j]=a[i];
      j--;
    }
    for(i=j;i>=0;i--){
      a[i]='0';
    }
    if(t==-1){
      for(i=0;i<=4;i++)
        a[i]=a[i+1];
      a[5]='.';
      t=5;
    }            
    j=0;
    for(i=0;i<=5;i++){
      if(i!=t){
   
        b[120+j]=a[i]-48;
        c[j]=a[i]-48;
        j++;
      }
    }
   
    for(i=120;i<=124;i++){
      if(b[i]!=0){
        s=i;
        break;
      }
    } 
                           
    for(i=2;i<=n;i++){
      s=calc(b,s,c);
    }
     
   _print(b,t,n);  

  }
 
}
int calc(int b[],int start,int c[]){
  int e[6],i,j,d[125]={0},v;
  for(i=124;i>=start;i--){
    e[0]=0;
    e[5]=0;
    for(j=4;j>=0;j--){
      e[j+1]+=b[i]*c[j]%10;
      e[j]=b[i]*c[j]/10;
      if(e[j+1]>=10){
        e[j+1]-=10;
        e[j]+=1;
      }
    }
         
    for(j=5;j>=0;j--){
                    
      d[i-5+j]+=e[j];
 
      if(d[i-5+j]>9){
        d[i-5+j]-=10;
        d[i-6+j]+=1;
      }
  
    }
  }
   
  v=-1;
  for(i=start-5;i<=124;i++){
    if(d[i]!=0&&v==-1){ 
      v=i;
    }
    b[i]=d[i]; 
  }
  return v;                       
}                                                            
void _print(int b[],int t,int n){
  char f[126];
  int k,i,u=-1,w;
  k=125;
  if(125-k==n*(5-t)){
      f[k]='.';
      k--;
      if(u==-1)
        u=k;
    }                  
  for(i=124;i>=0;i--){
    f[k]=b[i]+48;
    if(f[k]!='0'&&u==-1){
      u=k;
    }  
    k--;
    
    if(125-k==n*(5-t)){
      f[k]='.';
      k--;
      if(u==-1)
        u=k;
    }                   
  }
  w=0;
  
  for(i=0;i<=u;i++)
    if(f[i]!='0'||w==1){
      printf("%c",f[i]);
      w=1;
    }
                      
printf("\n");      
                            
}       


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