问题 B: Kids’ Riddle
时间限制: 1 Sec 内存限制: 512 MB提交: 31 解决: 8
[ 提交][ 状态][ 讨论版]
题目描述
Friends, have you ever taken the April Fools Contest 2017 at Codeforces? There is a problem called Kids’ Riddle. The problem description is given below: Programmers’ kids solve this riddle in 5 to 10 minutes. How fast can you do it? After long time thinking, the authors of our problem found out the rule. Just count the number of holes in hexadecimal notation. And now, it becomes the problem to you. Please solve the Kids’ Riddle problem.
输入
The input contains a single integer n(0 ≤ n ≤ 2000000000).
输出
Output a single integer.
样例输入
61441
样例输出
2
提示
The hexadecimal notation of 61441 is F001, there are two holes in it.
就是让你找这个数十六进制下的圈的个数
#include <bits/stdc++.h>
using namespace std;
int a[16] = { 1,0,0,0,1,0,1,0,2,1,1,2,0,1,0,0 };
int main()
{
int n;
while(~scanf("%d", &n))
{
int cnt = a[n % 16];
n /= 16;
while (n)
{
cnt += a[n % 16];
n /= 16;
}
printf("%d\n", cnt);
}
}