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 |
精简算法测试OK为何错呢?#include<iostream> #include<string.h> #include<math.h> using namespace std; int main() { long n;int a[64]; while(cin>>n&&n) { memset(a,0,64); int i=0,k=0; while(n) { a[i++]=n%2; n/=2; } for(int j=0;j<i;j++) { if(a[j]==1&&a[j+1]==0) {a[j]=0;a[j+1]=1;break;} if(a[j]==1&&a[j+1]==1) {k++;a[j]=0;} } for(int j=0;j<k;j++) a[j]=1; long s=0; for(int j=0;j<=i;j++) { s+=a[j]*pow(2,j); } cout<<s<<endl; } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator