Problem 2017-字符串统计

题目链接:acm.hdu.edu.cn/showproblem.php?pid=2017

题目描述:

Problem Description

对于给定的一个字符串,统计其中数字字符出现的次数。
 
Input
输入数据有多行,第一行是一个整数n,表示测试实例的个数,后面跟着n行,每行包括一个由字母和数字组成的字符串。
 
Output
对于每个测试实例,输出该串中数值的个数,每个输出占一行。
 
Sample Input
2
asdfasdf123123asdfasdf
asdf111111111asdfasdfasd
 
Sample Output
6
9
 1 #include<cstdio>
 2 using namespace std;
 3 int main()
 4 {
 5     int n;
 6     scanf("%d",&n);
 7     while(n--){
 8         char a[1000],*t;
 9         int cnt=0;
10         scanf("%s",a);
11         t=a;
12         while(*t){
13             if('0'<=*t && *t<='9'){
14                 cnt++;
15             }
16             t++;
17         } 
18         printf("%d
",cnt);
19     }
20     return 0;
21  }
原文地址:https://www.cnblogs.com/lan-xin/p/8453955.html