输入一段长英文字符串,统计其中数字个数,如果数字个数超过10,则打印输出“more”,如果数字个数小于等于10,则打印输出“less”。
include <iostream>
#include <string>
using namespace std;
int main() {
int count = 0; // 用于统计数字个数
string input; // 存储输入的字符串
getline(cin, input); // 获取一行输入的字符串
for (int i = 0; i < input.length(); i++) {
if (isdigit(input[i])) {
count++; // 如果字符是数字,则计数器加1
}
}
if (count > 10) {
cout << "more" << endl;
} else {
cout << "less" << endl;
}
return 0;
}