以下问题均假定输入的 n 为不超过 2^31−1 的非负整数。 假设输入为非负整数,则程序输出的第一个数一定不小于第二个数。( )
#include <iostream>
using namespace std;
int main() {
int n;
cin >> n;
int x = 1, y = 1;
while (n > 0) {
if (n % 2 == 0) {
++x;
} else {
++x;
++y;
}
n = n / 2;
}
cout << x << ' ' << y << endl;
return 0;
}
正确
错误