0
点赞
收藏
分享

微信扫一扫

761. 字符串中的数字个数


文章目录

  • ​​Question​​
  • ​​Ideas​​
  • ​​Code​​

Question

输入一行字符,长度不超过 100,请你统计一下其中的数字字符的个数。

输入格式
输入一行字符。注意其中可能包含空格。

输出格式
输出一个整数,表示字数字字符的个数。

输入样例:
I am 18 years old this year.
输出样例:
2

Ideas

遍历字符串

Code

// 0 48
#include <iostream>
#include <cstdio>
#include <string>

using namespace std;

int main()
{
string s;
getline(cin, s);

int n = 0;
for (int i = 0; i < s.size(); i ++)
{
if ('0' <= s[i] && s[i] <= '9')
n ++;
}

cout << n;
return 0;
}


举报

相关推荐

0 条评论