code4sk/c/sourcecode/朱森森带领的奇妙冒险/2022-2023第二学期单开班第3次月考/统计字符串中数字字符的个数.cpp
2023-12-15 22:38:26 +08:00

39 lines
No EOL
692 B
C++

/* 7-6 统计字符串中数字字符的个数
分数 10
作者 颜晖
单位 浙大城市学院
输入一个字符串,统计其中数字字符('0'……'9')的个数。
输入格式:
输入在一行中给出一个不超过80个字符长度的、以回车结束的非空字符串。
输出格式:
输出所统计的数字字符的个数。
输入样例:
It's 512?
输出样例:
3
代码长度限制
16 KB
时间限制
400 ms
内存限制
64 MB */
#include <stdio.h>
int main()
{
int cnt = 0;
char str[81];
gets(str);
for (int i = 0; str[i] != 0; i++)
{
if (str[i] >= '0' && str[i] <= '9')
cnt++;
}
printf("%d", cnt);
return 0;
}