B2109 统计数字字符个数
我今天提交了这一题,第一次提交是这样的:
#include <iostream>
#include <string>
using namespace std;
string s;
int n;
int main(){
getline(cin, s);
for (int i = 0; i <= s.length() - 1; i++){
if (s[i] <= '9' && s[i] >= '0'){
n++;
}
}
cout << n;
return 0;
}
第二遍是这样的:
#include <iostream>
#include <string>
using namespace std;
string s;
int n;
int main(){
getline(cin, s);
for (int i = 0; i <= s.length() - 1; i++){
if (s[i] <= '9' && s[i] >= '0'){
n++;
}
}
cout << n << endl;
return 0;
}
现在一个<<endl这么重要吗?价值可真是不容小觑