tj
2025-08-23 18:37:35
发布于:福建
1阅读
0回复
0点赞
#include <bits/stdc++.h>//万能头
using namespace std;//命名空间
string str;//定义这个字符串
long long count_letters , count_digits , count_others;
/*
count_letters:字母统计变量
count_digits:数字统计变量
count_others:其他字符统计变量
*/
int main() {//主函数
getline(cin , str);//因为输入包含空格,所以使用getline
for (int i = 0 ; i < str.length() ; i++) {//遍历字符串
if (str[i] != '?') {//首先先保证下标i是?
//18~21统计个数
if (str[i] >= 'a' && str[i] <= 'z') {
count_letters++;
}else if (str[i] >= '0' && str[i] <= '9') {
count_digits++;
}else {
count_others++;
}
}
}
//27~30输出个数
cout << "Letters=" << count_letters << endl;
cout << "Digits=" << count_digits << endl;
cout << "Others=" << count_others << endl;
return 0;
}
这里空空如也
有帮助,赞一个