| ||||||||||
| 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>
#include<cmath>
using namespace std;
int main()
{
int a;
double sum;
int i,m,c;
while(scanf("%d",&a)&&a)
{
int str[50]={0};
m=0;
c=0;
sum=0;
while(a)
{
str[m++]=a%2;
a/=2;
}
for(i=0;i<m;i++)
{
if(str[i]==1&&str[i+1]==0)
{
str[i]=0;
str[i+1]=1;
break;
}
}
for(i=0;i<=m;i++)
{
if(str[i])
sum+=pow(2.0,i);
}
printf("%d\n",(int)sum);
}
return 0;
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator