统计出现的数字字符,遍历统计就好。
#include <cstdio>
const int MAX_SIZE = 10000;
char words[MAX_SIZE];
//#define yangyuan
int main()
{
#ifdef yangyuan
freopen("in", "r", stdin);
#endif // yangyuan
int n;
scanf("%d", &n);
getchar();
while (n--)
{
fgets(words, MAX_SIZE, stdin);
int count = 0;
for (int i = 0; i < MAX_SIZE && words[i] != '\0'; i++)
{
if (words[i] >= '0' && words[i] <= '9')
count++;
}
printf("%d\n", count);
}
return 0;
}

本文介绍了一种通过遍历字符串来统计其中数字字符数量的方法。使用C语言实现,程序读取输入并输出数字字符的总数。
213

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



