题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2017
题解:
一个循环,判断每个字符是否在数字的范围内即可。
AC代码:
#include <string>
#include <iostream>
using namespace std;
int main() {
int n;
string str;
while (cin >> n) {
while (n--) {
cin >> str;
int ans = 0;
for(int i = 0; i < str.size(); i++) {
if(str[i] - 48 >= 0 && str[i] - 48 <= 9){
ans++;
}
}
cout << ans << endl;
}
}
return 0;
}