Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

为什么数据测试都对,提交了还会WA?请高手指点

Posted by mxf at 2011-07-14 16:34:20
#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:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator