#include <iostream>
#include <string.h>
using namespace std;
int main()
{
string str;
cout << "请输入一个字符串:";
getline(cin,str);
cout << "Hello World!" << endl;
int upper=0,lower=0,digit=0,space=0,others=0;
for(size_t i=0;i<str.size();i++)
{
char c = str[i];
if(c >= 'A' && c <= 'Z')
{
upper++;
}
else if(c >= 'a' && c <= 'z')
{
lower++;
}
else if(c >= '0' && c <= '9')
{
digit++;
}
else if(c == ' ')
{
space++;
}
else
{
others++;
}
}
cout << "大写字母个数: " << upper << endl;
cout << "小写字母个数: " << lower << endl;
cout << "数字个数: " << digit << endl;
cout << "空格个数: " << space << endl;
cout << "其他字符个数: " << others << endl;
return 0;
}
8.5号 C++作业
最新推荐文章于 2024-08-09 10:25:03 发布