字符串统计
Total Submission(s): 73389 Accepted Submission(s): 40187
Problem Description
对于给定的一个字符串,统计其中数字字符出现的次数。
Input
输入数据有多行,第一行是一个整数n,表示测试实例的个数,后面跟着n行,每行包括一个由字母和数字组成的字符串。
Output
对于每个测试实例,输出该串中数值的个数,每个输出占一行。
Sample Input
2 asdfasdf123123asdfasdf asdf111111111asdfasdfasdf
Sample Output
6 9
Author
lcy
Source
#include <stdio.h>
#include <string.h>
int main()
{
int n=0,count=0,i=0;
char str[110]={0};
scanf ("%d",&n);
while (n--)
{
scanf ("%s",str);
for (count=0,i=0;i<strlen(str);i++)
if (str[i]>='0'&&str[i]<='9')
count++;
printf("%d\n",count);
}
return 0;
}
字符串中数字计数
本文介绍了一道编程题,要求统计给定字符串中数字字符的出现次数。输入为多个包含字母和数字的字符串,输出每个字符串中数字字符的数量。文章提供了完整的C语言代码示例。
525

被折叠的 条评论
为什么被折叠?



