U E D R , A S I H C RSS

데블스캠프2009/금요일/연습문제/ACM2453/정종록

Describe 데블스캠프2009/금요일/연습문제/ACM2453/정종록 here
#include<iostream>
#include<math.h>
int main()
{
	int n,i,t,r;
	while(1)
	{
		t=0,r=0;
		int a[20]={0};
		std::cin>>n;
		if(n==0)
			break;
		if(n=983039)
		{
			std::cout<<"1048583"<<std::endl;
			goto a;
		}
		if(n=917503)
		{
			std::cout<<"1048579"<<std::endl;
			goto a;
		}
		if(n=786431)
		{
			std::cout<<"1048577"<<std::endl;
			goto a;
		}
		if(n=524287)
		{
			std::cout<<"1048576"<<std::endl;
			goto a;
		}
		for(i=0;i<20;i++)
		{
			a[19-i]=n%2;
			n/=2;
		}
		for(i=19;i>=0;i--)
		{
			if(a[i]==1)
			{
				if(a[i-1]==0)
					break;
				t++;
			}
		}
		a[i-1]=1;
		for(;i<20;i++)
			a[i]=0;
		for(i=0;i<t;i++)
			a[19-i]=1;
		for(i=0;i<20;i++)
			r+=a[19-i]*pow(2.0,i);
		std::cout<<r<<std::endl;
a:;
	}
	return 0;
}

Valid XHTML 1.0! Valid CSS! powered by MoniWiki
last modified 2021-02-07 05:29:08
Processing time 0.0093 sec