Description

对于给定的一个字符串,统计其中数字字符出现的次数。

Input

输入数据有多行,第一行是一个整数n,表示测试实例的个数,后面跟着n行,每行包括一个由字母和数字组成的字符串。

Output

对于每个测试实例,输出该串中数值的个数,每个输出占一行。

Sample Input

2
asdfasdf123123asdfasdf
asdf111111111asdfasdfasdf

Sample Output

6
9
#include <iostream>
#include <cstdio>
#include <cstring>

using namespace std;

char str[10000];

int main()
{
    int n;

    scanf("%d", &n);
    //吃掉回车
    getchar();
    while(n--)
    {
        gets(str);
        int len = strlen(str);
        int cnt = 0;
        for (int i = 0; i < len; i++)
        {
            if (str[i]<='9' && str[i] >='0')
            {
                cnt++;
            }
        }
        printf("%d\n", cnt);
    }

    return 0;
}

 

Logo

一站式虚拟内容创作平台,激发创意,赋能创作,进入R空间,遇见同道,让优质作品闪耀发光。​

更多推荐