简答题 偏难
#22771

01 #include <iostream> 02 using namespace std; 03 04 int n; 05 int a[1000]; 06 0…

01 #include <iostream>

02 using namespace std;

03

04 int n;

05 int a[1000];

06

07 int f(int x)

08 {

09 int ret = 0;

10 for (; x; x &= x - 1) ret++;

11 return ret;

12 }

13

14 int g(int x)

15 {

16 return x & -x;

17 }

18

19 int main()

20 {

21 cin >> n;

22 for (int i = 0; i < n; i++) cin >> a[i];

23 for (int i = 0; i < n; i++)

24 cout << f(a[i]) + g(a[i]) << ' ';

25 cout << endl;

26 return 0;

27 }

未登录也能判分,登录后才会记录
答案与解析
正确答案:(缺答案,待补录)
这道题暂未补解析。