#include <bits/stdc++.h> #include #include #include #include #include #include using namespace std; int main() { int a, sum; long long int ans[100000]; int t = 0; cin >> a; while (a != 0) { ans[++t] = a % 2; a /= 2; } for (int i = t; i >= 1; i--) { if (ans[i] == 1) sum++; } cout << sum; }
共 1 条回复
sum 没有初始化为 0