思路 这道题本来想着要把输入的二进制求解出来,后来发现是没有必要的。我只需要在计算的过程中判断取模的结果是否为1,用一个计数器就可以了。 C语言版本 #include <stdio.h> int main() { int n; scanf("%d", &n); int count = 0; while (1) { if (n / 2 == 0) { count += 1; break; } if (n % 2 == 1) { count += 1; } n /= 2; } printf("%d\n", count); return 0...