C++ 9行代码搞定该问题
用iostream不用namespace显得我很抠门,所以把它换成了stdio.h。这样看起来就正常多了~
至于return 0嘛~
#include <stdio.h>
int n, ans, book[23] = {1,0,0,0,1,0,1,0,2,1,0,0,0,0,0,0,0,1,2,0,1,0,0};
char tmp[9];
int main() {
scanf("%d", &n);
sprintf(tmp, "%X", n);
for (auto& i : tmp) ans += book[i - '0'];
printf("%d", ans);
}
10行正经的代码
#include <stdio.h>
int n, ans, book[16] = {1,0,0,0,1,0,1,0,2,1,1,2,0,1,0,0};
int main() {
scanf("%d", &n);
do {
ans += book[n & 0xf];
n >>= 4;
} while(n);
printf("%d", ans);
}
tql
你甚至不愿意给它个namespace
这样可以再压榨一行