题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2017
题目大意:给你段字符串,求出字符串中含有数字字符的个数
解题思路:
字符串输入输出的基本应用:http://c.biancheng.net/cpp/html/3106.html https://blog.csdn.net/qq_29924041/article/details/54351384
scanf() 只吃实体字符串,空格回车不吃
gets() 空格回车都吃,吃到回车为止
getchar() 啥都吃,一次吃一个
PS: 本题用到的不太多,所以只是肤浅介绍的写一下本题相关,有什么更好的以后再更新
代码:
1 #include<iostream>
2 #include<cmath>
3 #include<iomanip>
4 #include<cstdio>
5 #include<cstring>
6 #include<algorithm>
7 using namespace std;
8 int main()
9 {
10 int n;
11 char str[105];
12 while(cin >> n)
13 {
14 getchar();
15 while(n --)
16 {
17 int q = 0;
18 gets(str);
19 int len = strlen(str);
20 for(int i = 0; i < len; i ++)
21 {
22 if(str[i] >= '0' && str[i] <= '9')
23 q ++;
24 }
25 cout << q << endl;
26 }
27 }
28 }