csppass
连续 00 XP登录 / 注册
202119判断题枚举与模拟普及-

程序(一):输入1 511998的输出

题目

阅读下面的程序,回答问题。 #include <iostream> using namespace std; int n; int a[1000]; int f(int x) { int ret = 0; for (; x; x &= x - 1) ret++; return ret; } int g(int x) { return x & -x; } int main() { cin >> n; for (int i = 0; i < n; i++) cin >> a[i]; for (int i = 0; i < n; i++) cout << f(a[i]) + g(a[i]) << ' '; cout << endl; return 0; } 判断题:当输入为“1 511998”时,输出为“18”。( )

考点拆解
程序阅读与结果判断
易错提醒
阅读程序题要按变量变化顺序手推,不要跳步
选择题要检查单位、边界和题目中的否定词