统计数字字符个数

Descriprion

输入一行字符,统计出其中数字字符的个数。

Format

Input

一行字符串,总长度不超过255。

Output

输出为1行,输出字符串里面数字字符的个数。

#include<iostream>
#include<cstring>
using namespace std;
char S[257];
int main() {
	int ct=0;
	scanf("%[^\n]",S+1);
	int a=strlen(S+1);
	for(int i=1;i<=a;i++){
		if(S[i]>='0' && S[i]<='9'){
			ct++;
		}
	}
	printf("%d",ct);
	return 0;
}
posted @ 2025-03-02 14:47  Frank_TMQ  阅读(124)  评论(0)    收藏  举报