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 |
谁能帮我看看哪里错了啊。。。程序虽然写的搓了点。。。但是好像也没有什么错的吧#include <iostream> #include <math.h> using namespace std; int main () { // freopen("jieguo1.txt","w",stdout); // freopen("shuzi.txt","r",stdin); int t,sum,i,k,j; bool a[150]; cin>>t; while(t!=0) { for(i=0;i<149;i++)a[i]=0; sum=0; for(i=0;;i++) { a[i]=t%2; t=t/2; if(t==0)break; } k=i; for(i=0;i<=k;i++) { if(a[i]==1) { if(a[i+1]==0) { a[i]=0; a[i+1]=1; break; } else { j=i; while(a[j-1]==0) { a[j]=0; a[j-1]=1; j--; } } } } for(i=k+5;i>=0;i--) sum+=a[i]*pow(2.0,i); cout<<sum<<endl; cin>>t; } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator