R - 字符串统计 HDU - 2017

R - 字符串统计  HDU - 2017 

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

Input

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

Output

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

Sample Input

2
asdfasdf123123asdfasdf
asdf111111111asdfasdfasdf

Sample Output

6
9

代码示例:

#include<stdio.h>
#define N 100
int main(){
    int n;
    while(scanf("%d",&n)!=EOF){
        char a[N];
        getchar();
        while(n--){
            int i=0,b=0;
            while(1){   //运用了死循环,满足条件后break
                scanf("%c",&a[i]);
                if(a[i]==10) break;
                else if(a[i]>='0'&&a[i]<='9') b++;
                i++;
            }
            printf("%d\n",b);
        }
    }
}
扫描二维码关注公众号,回复: 10503961 查看本文章
发布了24 篇原创文章 · 获赞 7 · 访问量 1899

猜你喜欢

转载自blog.csdn.net/weixin_43426647/article/details/84771874