#include <iostream>
using namespace std;
int main()
{
string str;
cout << "请输入>>";
getline(cin,str);
cout << str <<endl;
int t1=0; //大写字母个数
int t2=0; //小写字母个数
int t3=0; //数字个数
int t4=0; //空格个数
int t5=0; //其他字符个数
for(int i=0; i<str.size(); i++)
{
if(str.at(i) >= 'A' && str.at(i) <= 'Z'){
t1++; //大写字母
}else if(str.at(i) >= 'a' && str.at(i) <= 'z'){
t2++; //小写字母
}else if(str.at(i) >= '0' && str.at(i) <= '9'){
t3++;//数字
}else if(' ' == str.at(i)){
t4++; //空格
}else{
t5++;
}
}
cout << "大写字母 " << t1 << " 个 " << endl;
cout << "小写字母 " << t2 << " 个 " << endl;
cout << "数字 " << t3 << " 个 " << endl;
cout << "空格 " << t4 << " 个 " << endl;
cout << "其他字符 " << t5 << " 个 " << endl;
return 0;
}
10.7C++作业
最新推荐文章于 2024-07-12 16:34:36 发布