1、http://acm.fzu.edu.cn/problem.php?pid=2123
2、题目大意:
Problem 2123 数字的孔数
Accept: 176 Submit: 248
Time Limit: 1000 mSec Memory Limit : 32768 KB
Problem Description
S得到一个数,他想知道这个数每一位上的数字的孔数之和。1,2,3,5,7这几个数字是没有孔的,0,4,6,9都有一个孔,8有两个孔。
Input
输入数据的第一行为一个数T表示数据组数。接下来T行,每行输入一个正整数n(1<=n<=1000),表示要求数字孔数之和的数。n不会有前导0。
Output
对于每组数据输出一行一个整数,表示该数的每一位上的数字的孔数之和。
Sample Input
242669
Sample Output
13
Source
福州大学第十届程序设计竞赛
二、AC代码:
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
char str[10];
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
scanf("%s",str);
int len=strlen(str);
int count=0;
for(int i=0;i<len;i++)
{
if(str[i]=='0' || str[i]=='4' || str[i]=='6' || str[i]=='9')
count++;
else if(str[i]=='8')
count+=2;
}
printf("%d\n",count);
}
return 0;
}