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

help~~!!

Posted by 225603 at 2012-10-07 10:26:13 on Problem 1001
#include<iostream>
using namespace std;
int n,la,lb,lc,lx;    
int a[160], b[160], c[160];
char r[7];  

void bigc()
{
     for (int i=1;i<=la;i++)
       for (int j=1;j<=lb;j++) c[i+j-1]=c[i+j-1]+a[i]*b[j]; lc=la+lb;
     for (int i=2;i<=lc;i++) {c[i]=c[i]+c[i-1]/10; c[i-1]=c[i-1]%10;}
     while (c[lc]%10!=c[lc]){lc++; c[lc]=c[lc-1]/10; c[lc-1]=c[lc-1]%10;}
     for (int i=1;i<=lc;i++) a[i]=c[i]; la=lc;  
     for (int i=0;i<=160;i++) c[i]=0;
}

void print() 
{
     while (a[la]==0&&la>lx+1&&la>1) la--; 
     while (a[1]==0&&lx>0) 
      {lx--; la--;for (int i=1;i<=la;i++) a[i]=a[i+1];}
     for (int i=la; i>=lx+1;i--) cout<<a[i];
     if (!(lx==1&&a[1]==0)&&(lx>0)) cout<<'.';
     for (int i=lx;i>=1;i--) cout<<a[i]; 
     cout<<endl; 
}

int main()
{
    int rz,xsd;
    
    while(cin>>r)
    {
        la=0;
        for (int i=1;i<=6;i++) 
        {
            la++;   
            if (r[i-1]=='.') {xsd=i;la--;} else a[la]=b[la]=r[i-1]-'0'; 
        }
        lx=la-xsd+1;  if (lx<0) lx=0;
        for (int i=1;i<=la;i++) b[i]=a[la-i+1];
        for (int i=1;i<=la;i++) a[i]=b[i];
        cin>>n; lx=lx*n; lb=la; 
        for (int i=0;i<=160;i++) c[i]=0;
        for (int i=1; i<n;i++) bigc();
        print();
    }
    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