1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | #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; } |
0 of 6 Questions completed
Questions:
You have already completed the quiz before. Hence you can not start it again.
Quiz is loading…
You must sign in or sign up to start the quiz.
You must first complete the following:
0 of 6 Questions answered correctly
Your time:
Time has elapsed
You have reached 0 of 0 point(s), (0)
Earned Point(s): 0 of 0, (0)
0 Essay(s) Pending (Possible Point(s): 0)
1、输入的 n 等于1001 时,程序不会发生下标越界。( )
2、输入的 a[i]
必须全为正整数,否则程序将陷入死循环。( )
3、当输入为 5 2 11 9 16 10
时,输出为 3 4 3 17 5
。( )
4、当输入为 1 511998
时,输出为 18。( )
5、将源代码中 g
函数的定义(14 – 17 行)移到 main
函数的后面,程序可以正常编译运行。( )
6、当输入为 2 -65536 2147483647
时,输出为 ( )。