#include<iostream>
#include<string>
#define m 80
using namespace std;
int main()
{
int i, j, upper, lower, num, space, other;
char str[3][m];
upper = 0, lower = 0, num = 0, space = 0, other = 0;
for (i = 0; i < 3; i++)
{
cout << "please input the line:" << i + 1;
cin >> str+;
}
cout << endl;
for (i = 0; i < 3; i++)
{
for (j = 0; j < m && str+[j] != '\0'; j++)
{
if (str+[j] >= 'A'&&str+[j] <= 'Z')
upper++;
else if (str+[j] >= 'a'&&str+[j] <= 'z')
lower++;
else if (str+[j] >= '0'&&str+[j] <= '9')
num++;
else if (str+[j] == ' ' || str+[j] == '\t')
space++;
else
other++;
}
}
cout << "The statistical results are as follows:" << endl;
cout << "大写字母有" << upper << "个" << endl;
cout << "小写字母有" << lower << "个" << endl;
cout << "数字有" << num << "个" << endl;
cout << "空格有" << space << "个" << endl;
cout << "其他字符有" << other << "个" << endl;
system("pause");
return 0;
}
有一篇文章,共3行文字,每行80个字符。要求分别统计其中英文大写字母,小写字母,数字,空格以及其他字符的个数
于 2022-05-02 19:10:48 首次发布