Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
Re:我是新手 累计奋战10多个小时 终于accepted!代码如下,和大家交流一下In Reply To:我是新手 累计奋战10多个小时 终于accepted!代码如下,和大家交流一下 Posted by:yanzhengfei at 2009-05-19 22:54:20 > #include<iostream> > using namespace std; > > void calculate(int a[],int n,int tag) > { > int m,i,j,s,t,k,g=0,flag; > int b[200],c[200],d[200]; > for(i=0;i<200;i++)b[i]=d[i]=c[i]=-1; > for(i=0;a[i]!=-1;i++) > b[i]=a[i]; > n--; > while(n) > { > flag=1;k=-1; > for(i=0;a[i]!=-1;i++) > { > t=0;s=0;g=0;k++; > for(j=0;b[j]!=-1;j++) > { > m=(a[i]*b[j])%10+t; > t=(a[i]*b[j])/10; > if(m>=10){c[g]=m%10;t++;} > else c[g]=m; > g++; > }c[g]=t;g=0; > if(flag) > { > for(j=0;c[j]!=-1;j++) > d[j]=c[j]; > flag--; > } > else > for(j=0;c[j]!=-1;j++) > { > m=d[g+k]+c[j]; > if((d[g+k+1]==-1)&&(c[j+1])!=-1)d[g+k+1]=0; > t=m%10+s; > s=m/10; > if(t>=10){d[g+k]=t%10;s++;} > else d[g+k]=t; > g++; > } > > for(j=0;j<200;j++)c[j]=-1; > }//for > > for(i=0;i<200;i++) > b[i]=d[i]; > for(i=0;i<200;i++) > d[i]=-1; > n--; > }//while > j=0;flag=0; > for(i=0;i<200;i++) > { > if(!b[i]&&tag>i)j++; > else > break; > } > for(i=199;i>=j;i--) > { > if(b[i]!=-1) > { > if(b[i]==0) > {if(flag)cout<<b[i];} > else > {cout<<b[i];flag=1;} > } > if(i==tag&&tag!=j){cout<<".";flag=1;} > } > cout<<endl; > } > > int main() > { > int n,i,j,tag; > int a[7];char str[7]; > while(cin>>str>>n) > { > tag=1; > for(i=0;i<7;i++)a[i]=-1; > for(i=0;str[i]!='\0';i++) > { > if(str[i]!='.')tag++; > else > { > for(;i<7;i++) > str[i]=str[i+1]; > break; > } > } > for(i=0;str[i]!='\0';i++); > for(j=0;j<=i-1;j++) > a[j]=str[i-1-j]-'0'; > tag=n*(6-tag); > calculate(a,n,tag); > } > return 0; > } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator