1150: 数数多少个整数
时间限制: 1 Sec 内存限制: 128 MB
提交: 118 解决: 190
[提交] [状态] [讨论版] [命题人:eilene]
题目描述
小明的老师给小明出了一道题目:数数一篇文章出现了多少个数字,请你帮帮他吧。
输入
输入一个字符串,由空格、英文字母、数字组成,以回车结束,长度小于1000。
输出
输出整数个数(不是数字字符个数哦)。
样例输入 Copy
5436grh 74h74 57 74rg 63664greg743
样例输出 Copy
7
#include <stdio.h>
#include<string.h>
int main()
{
char str[1001];
int i,count=0;
gets(str);
if(str[0]>='0'&&str[0]<='9')
{
count++;
}
for(i=strlen(str)-1;i>=0;i--)
{
if((str[i]>='0'&&str[i]<='9')&&(str[i-1]>='a'
&&str[i-1]<='z'||str[i-1]>='A'
&&str[i-1]<='Z'||str[i-1]==' '))
count++;
}
printf("%d\n",count);
return 0;
}