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:hawk兄能帮忙看一下我的程序是超时多少呢?是不是死循环?谢谢。In Reply To:hawk兄能帮忙看一下我的程序是超时多少呢?是不是死循环?谢谢。 Posted by:anykey001 at 2005-04-01 11:21:20 #include <iostream.h> const char endchar='Z'; const int size=150; inline int mylen(char *source) { int i=0; for(;*source!=endchar;source++) i++; return i-1; } void main() { char result[size];result[0]='k'; char buf[size];buf[0]='k'; char buf2[size];buf2[0]='k'; char old[size];old[0]='k'; char ch; int exp,pointpos,i,j,h,k,len,temp,current,oldlen,n; bool flag=false; while(cin.eof()!=1) { flag=false; for(i=1,h=1;;h++) { cin.get(ch); if(ch==' ') break; if(ch!='.' && ch!='0') { result[i]= ch; flag=true; ++i; } else if(ch=='.') pointpos= 6-h; else if(ch=='0' && flag==true) { result[i]=ch; ++i; } } result[i]=endchar; len=mylen(result); oldlen=len; for(i=1;i<=len;i++) result[i]=result[i]-'0'; for(j=1;j<=len;j++) buf[j]=result[len+1-j]; for(j=1;j<=len;j++) { result[j]=buf[j]; old[j]=buf[j]; } cin>>exp; for(k=1;k<exp;k++) { result[0]='k'; len=mylen(result); for(j=1;j<=len;j++) buf[j]=result[j]; for(j=1;j<=len+1;j++) result[j]=0; for(i=1;i<=len;i++) { temp=0; for(j=1;j<=oldlen;j++) { current=result[j+i-1]+buf[i]*old[j]+temp; temp=current/10; result[j+i-1]=current%10; } result[j+i-1]=temp; } if(result[j+i-2]==0) result[j+i-2]=endchar; else result[j+i-1]=endchar; } buf[0]='k'; buf2[0]='k'; pointpos*=exp; len=mylen(result); if(pointpos<len) { for(i=1,j=1;j<=len;) { if(i!=pointpos+1) { buf2[i]=result[j]; i++; j++; } else { buf2[i]='.'; i++; } } buf2[i]=endchar; } else { for(i=1,j=1;j<=len;) { buf2[i]=result[j]; i++; j++; } for(;i<=pointpos;i++) buf2[i]=0; buf2[i]='.'; buf2[i+1]=endchar; } len=mylen(buf2); flag=false; for(i=1;i<=pointpos;i++) { if(buf2[i]!=0) { buf2[i-1]=endchar; flag=true; break; } } if(flag==false) buf2[pointpos+1]=endchar; for(i=len;buf2[i]!=endchar;i--) { if(buf2[i]!='.') cout<<int(buf2[i]); else cout<<buf2[i]; } cout<<endl; cin.ignore(1); } } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator