Number of holes
Welcome to the world of my C language
topic
Problem Description
S gets a number. He wants to know the sum of the number of holes in each digit of this number. The numbers 1,2,3,5,7 have no holes, 0,4,6,9 all have one hole, and 8 has two holes.
Input
In the first line of input data, a number T represents the number of data groups. In the next T line, enter a positive integer n (1<=n<=1000) in each line, which represents the number of required digital holes. n will not have a leading 0.
Output
For each group of data, an integer is output in one line, which represents the sum of the number of holes in each digit of the number.
Sample Input
2
42
669
Sample Output
1
3
answer
Shown below 实现代码
.
#include <stdio.h>
#include <iostream>
#include <string.h>
#include <algorithm>
using namespace std;
int quan[11] = {
1, 0, 0, 0, 1, 0, 1, 0, 2, 1};
int main()
{
int T;
int i, j, k;
while(scanf("%d",&T) != EOF)
{
for(i = 0; i < T; i ++)
{
int sum = 0;
int num;
int Num[5];//用于记录数字中的每个数
cin >> num;
for(j = 0; num > 9; j++)
{
Num[j] = num % 10;
num = num / 10;
}
Num[j] = num;
for(k = 0; k <= j; k++)
{
sum += quan[Num[k]];//假设Num[k]=9,9的孔数就在quan[9]里
}
cout << sum << endl;
}
}
return 0;
}
Thoughts on this question
The content of this block may come from textbooks or other websites. If infringement is involved, please contact me to delete it. Thank you~
This question does not necessarily require if for the number of laps, hehe~
above.