T1103 统计数字字符个数 ##计蒜客 C++
"输入一行字符,统计出其中数字字符的个数。"
输入格式
一行字符串,总长度不超过 255。
输出格式
输出为 1 行,输出字符串里面数字字符的个数。 (输出时每行末尾的多余空格,不影响答案正确性。)
样例输入
Peking University is set up at 1898.
样例输出
4
##代码如下##
#include <iostream>
#include <cstring>
using namespace std;
int main(){
char s[257];
int count = 0;
cin.getline(s,256);
int l = strlen(s);
for(int i=0; i<l; i++){
if(s[i]>='0' && s[i]<='9')
count ++;
}
cout << count;
return 0;
}