A. Raising Bacteria

计算一下x的bitcount就是答案。

 1 #include <iostream>
 2 #include <cstdio>
 3 #include <cstring>
 4 #include <algorithm>
 5 using namespace std;
 6 
 7 int bitcount(int x)
 8 {
 9     int ans = 0;
10     while(x)
11     {
12         if(x & 1) ans++;
13         x >>= 1;
14     }
15     return ans;
16 }
17 
18 int main()
19 {
20     int x; scanf("%d", &x);
21     printf("%d\n", bitcount(x));
22 
23 
24     return 0;
25 }
代码君

相关文章:

  • 2021-06-14
  • 2022-02-11
  • 2021-06-11
  • 2022-02-18
  • 2021-07-27
  • 2021-08-19
  • 2022-02-28
猜你喜欢
  • 2022-12-23
  • 2021-11-29
  • 2021-10-18
  • 2021-08-08
  • 2021-12-05
  • 2022-01-29
  • 2021-11-08
相关资源
相似解决方案