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

咳咳随手贴(sb题目= =

Posted by 1032505101 at 2017-03-04 22:25:59 on Problem 1001
#include<iostream>
#include<cstring>
#include<cstdio>
using namespace std;
#define ql(a) memset(a,0,sizeof(a))
int sum[100005],pd,a[100005],b[100005];
void mul(int a[],int b[])
{
 int i,j,k;
 sum[0]=a[0]+b[0]-1;
 for (i=1;i<=a[0];i++)
 for (j=1;j<=b[0];j++){
    sum[i+j-1]+=a[i]*b[j];
 }
 for (i=1;i<=sum[0];i++){
    if (sum[i]>9) {sum[i+1]+=sum[i]/10;sum[i]%=10;}
    if (sum[sum[0]+1]) sum[0]++;
 }
 //for (i=sum[0];i>=1;i--) cout<<sum[i];cout<<endl;
 for(i=0;i<=sum[0];i++) b[i]=sum[i];
}
void print1(int asum[])
{
    int qd=0;
  for (int i=asum[0];i>=1;i--) {if (asum[i]!=0) qd=1;
        if (qd) cout<<asum[i];}
  cout<<endl;
}
void print2(int bsum[])
{//cout<<bsum[0]<<" "<<pd<<endl;
    int qd0=0,hd0=0,point=0,jb=1;
    for (int i=1;i<=pd;i++){
        if (bsum[i]!=0) point=1;
        if (!point) bsum[i]=-1;
    }int ttt=1;if (bsum[pd]==-1) jb=0;
  for (int i=bsum[0], j=1;i>=1;i--,j++) {//if (bsum[0]-j==pd) {cout<<'.';point=1;}
      ttt=1;
      if (i>pd&&bsum[i]!=0) qd0=1;
      if (i>pd&&bsum[i]==0&&qd0==0) ttt=0;
        if (bsum[i]<0) continue;
       if (ttt) cout<<bsum[i];
if (bsum[0]-j==pd&&jb) {cout<<'.';point=1;}
  }cout<<endl;
}
int main()
{
    int n,m,i,j,k,t,p;
    char s[10005];
    while(cin>>s>>n){ql(a),ql(b),ql(sum);
    k=0;pd=-1;b[0]=b[1]=1;
    for (i=strlen(s)-1;i>=0;i--){
    if (s[i]=='.') {pd=strlen(s)-i-1;continue;}
    a[++k]=s[i]-'0';
    }
    a[0]=k;
    for (i=1;i<=n;i++){ql(sum);
    mul(a,b);
    }
    if(pd==-1) print1(b);
    else {pd*=n;print2(b);}
    }
    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