Description
对于给定的一个字符串,统计其中数字字符出现的次数。
Input
输入数据有多行,第一行是一个整数n,表示测试实例的个数,后面跟着n行,每行包括一个由字母和数字组成的字符串。
Output
对于每个测试实例,输出该串中数值的个数,每个输出占一行。
Sample Input
2 asdfasdf123123asdfasdf asdf111111111asdfasdfasdf
Sample Output
6 9
#include<stdio.h>
int main(){
int n;
scanf("%d\n",&n); //输入后面有转行,不仅在输出中,输入中也有。
char str[10000]; //虽然不知道字符串的长度,但是不用动态开辟。!!n在编译的时候并没有赋值,不能作为数组下标
while(n--)
{
int i=0,counts=0;
gets(str);
while(str[i]!='\0') //字符串结束的表示系统自动带0
{
if((str[i]<='9')&&(str[i]>='0'))
counts++;
i++;
}
printf("%d\n",counts);
}
return 0;
}