简单题, 熟悉系统...
#include <stdio.h> #define RADIX 2 int calOneCount(int val) { int temp = val; int count = 0; int preBit = 0; while(temp) { preBit = temp % RADIX; temp /= RADIX; if(preBit == 1) count++; } return count; } int main() { int inputVal = 0; int result = 0; int count = 0; while(scanf("%d", &inputVal) && inputVal != 0) { count = calOneCount(inputVal); result = inputVal + 1; while(calOneCount(result) != count) result++; printf("%d/n", result); } return 0; }