#include <string>
#include <cctype>
using namespace std;
int main()
{
string str;
cout << "输入一个字符串分别统计大写字母、小写字母、空格的个数:" << endl;
getline(cin,str);
int a = 0,b = 0,c = 0,d = 0;
for(string::size_type i = 0;i < str.size();i++)
{
if(isupper(str[i]))
a++;
if(isdigit(str[i]))
b++;
if(isspace(str[i]))
c++;
if(ispunct(str[i]))
d++;
}
cout << "大写字母: " << a << endl;
cout << "小写字母: " << str.size() - a - b - c - d << endl;
cout << "数字的个数: " << b << endl;
cout << "空格的个数: " << c << endl;
cout << "标点符号的个数: " << d << endl;
return 0;
}
版权声明:本文为sp353846548原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。