poj2453

简单题

View Code
#include <iostream>
#include
<cstdlib>
#include
<cstring>
#include
<cstdio>
using namespace std;

int count(int x)
{
int ret = 0;
while (x > 0)
{
if (x % 2 == 1)
ret
++;
x
/= 2;
}
return ret;
}

int main()
{
//freopen("D:\\t.txt", "r", stdin);
int n;
while (scanf("%d", &n) != EOF && n != 0)
{
int cnt = count(n);
while (n++)
if (cnt == count(n))
{
printf(
"%d\n", n);
break;
}
}
return 0;
}
posted @ 2011-04-30 15:47  金海峰  阅读(205)  评论(0编辑  收藏  举报