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:1001OLE

Posted by ZaakDov at 2008-12-09 21:51:28 on Problem 1001 and last updated at 2008-12-09 21:52:05
In Reply To:1001OLE Posted by:ZaakDov at 2008-12-09 21:51:09
Code*

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
//#include <time.h>
int calc(int[],int,int[]);
void _print(int [],int,int);
int main(){
  char a[6];
  //time_t t1,t2;
  int n,i,t,j,b[125]={0},c[5],s; 
  while(1){
    for(i=0;i<=124;i++)
      b[i]=0;
    scanf("%s",a);
    scanf("%d",&n);
   // t1=time(NULL);
    for(i=0;i<=5;i++){
      if(a[i]=='.'){
        t=i;             
      }  
    }
    j=0;
    for(i=0;i<=5;i++){
      if(i!=t){
   //b[] need initialize
        b[120+j]=a[i]-48;
        c[j]=a[i]-48;
        j++;
      }
    }
    //, 对于0 
    for(i=120;i<=124;i++){
      if(b[i]!=0){
        s=i;
        break;
      }
    } 
                           
    for(i=2;i<=n;i++){
      s=calc(b,s,c);
    }
/*Debug 
   for(i=0;i<=124;i++)
    printf("%d ",b[i]);
             printf("\n"); */          
   _print(b,t,n);  
  // t2=time(NULL);
 //  printf("%f",difftime(t2,t1));
  }
 
}
int calc(int b[],int start,int c[]){
  int e[6],i,j,d[125]={0},v,deb;
  for(i=124;i>=start;i--){
    e[0]=0;//init e[j]=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;
 
  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