题解
2024-11-30 09:46:22
发布于:浙江
2阅读
0回复
0点赞
#include <iostream>
#include <string>
#include <cctype> // for isalpha and isdigit
using namespace std;
int main() {
string input;
getline(cin, input); // 读取一行输入
// 去除终止符 "$?$"
size_t pos = input.find("$?$");
if (pos != string::npos) {
input = input.substr(0, pos);
}
int letters = 0;
int digits = 0;
int others = 0;
// 遍历字符串,统计各类字符的数量
for (char c : input) {
if (isalpha(c)) {
letters++;
} else if (isdigit(c)) {
digits++;
} else {
others++;
}
}
// 输出结果
cout << "Letters=" << letters << endl;
cout << "Digits=" << digits << endl;
cout << "Others=" << others << endl;
return 0;
}
这里空空如也
有帮助,赞一个