#include <iostream>
#include <cstring>
using namespace std;
int main() {
string s;
getline(cin , s);
int i = 0;
int a = 0 , b = 0 , c = 0;
while(s[i] != '\0')
{
if(s[i] >='a' && a<= 'z' ||s[i] >='A' && a<= 'Z') a++;
else if(s[i] >='0' && a<= '9') b++;
else c ++;
i ++;
}
cout << "字母:" <<a <<"个"<<endl;
cout << "数字:" <<b <<"个"<<endl;
cout << "其他:" <<c <<"个"<<endl;
return 0;
}
输入字符串,统计字符中的字母,数字,空格等其他字符个数
这篇文章展示了一个C++程序,通过getline函数获取用户输入的字符串,然后使用条件语句统计其中的字母、数字和非字母数字字符的数量。

被折叠的 条评论
为什么被折叠?



