Hang electric OJ - 2017 Statistics string

Please enjoy the way my rookie record knock of Code

Really I want to improve programming ability, most recently in Hangzhou electric brush page 11 OJ, eight said, my rookie code.

字符串统计
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 134795 Accepted Submission(s): 73932

Problem Description
for a given string, which count the number of numeric characters appear.

Input
input data a plurality of rows, a first row n is an integer, indicates the number of test cases, followed by a string of n rows, each row comprises a combination of letters and numbers.

Output
For each test case, the output value of the number of strings, each output per line.

Sample Input
2
asdfasdf123123asdfasdf
asdf111111111asdfasdfasdf

Sample Output
6
9

#include <iostream>
#include <string>

using namespace std;

int main() {
	int n;
	cin >> n;
	for (int i = 0; i < n; i++) {
		string s;
		cin >> s;
		int len = s.length();
		int count = 0;
		for (int j = 0; j < len; j++) {
			if (s[j] >= '0' && s[j] <= '9') count++;
		}
		cout << count << endl;
	}

	return 0;
} 
Released three original articles · won praise 0 · Views 81

Guess you like

Origin blog.csdn.net/qq_44296342/article/details/104097620