| ||||||||||
| 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 | |||||||||
调了很久。。。。还是WA. 哇哇!#include <iostream.h>
#include <math.h>
#include <stdio.h>
int main()
{
#ifndef ONLINEJUDGE
freopen("in.txt","r",stdin);
#endif
long n,k,len,m,sum,a[100],i;
while (cin>>n&&n!=0)
{
len=0;
memset(a,0,sizeof(a));
while (n>0)
{
len++;
a[len]=n%2;
n/=2;
}
k=0;
for (i=1;i<=len;i++) if (a[i]==1) break;
for (;i<=len;i++)
{
if (a[i]==0) break;
else k++;
}
if (i==len+1) len++;
a[i]=1;
for (m=i-1;m>=k;m--) a[m]=0;
for (;m>=1;m--) a[m]=1;
sum=0;
for (m=1;m<=len;m++)
sum+=long(powl(2,m-1))*a[m];
cout<<sum<<endl;
}
}
Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator