Description
小明的老师给小明出了一道题目:数数一篇文章出现了多少个数字,请你帮帮他吧。
Input
输入一个字符串,由空格、英文字母、数字组成,以回车结束,长度小于1000。
Output
输出整数个数(不是数字字符个数哦)。
Sample Input
5436grh 74h74 57 74rg 63664greg743
Sample Output
7
HINT
Source
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
int main()
{
char str[1002];
gets(str);
int i;
int count=0;
int flag=0;
for(i=0; i<strlen(str); i++)
{
if (isdigit(str[i]) && flag == 0)//sdigit是计算机C(C++)语言中的一个函数,主要用于检查参数是否为十进制数字字符
//<ctype.h>
{
flag=1;
count++;
}
if (!isdigit(str[i]))
flag = 0;
}
printf("%d\n",count);
return 0;
}