输入一行最多包含80个字符的英语句子,统计其中大写字母,小写字母,数字,空格和其他字符的数量
时间: 2024-06-13 09:05:47 浏览: 85
以下是统计英语句子中大写字母,小写字母,数字,空格和其他字符数量的C++代码:
```c++
#include <iostream>
#include <cstring>
using namespace std;
int main() {
char str[81];
int len, upper = 0, lower = 0, digit = 0, space = 0, other = 0;
cout << "请输入字符串:";
cin.getline(str, 81);
len = strlen(str);
for (int i = 0; i < len; i++) {
if (str[i] >= 'A' && str[i] <= 'Z') {
upper++;
} else if (str[i] >= 'a' && str[i] <= 'z') {
lower++;
} else if (str[i] >= '0' && str[i] <= '9') {
digit++;
} else if (str[i] == ' ') {
space++;
} else {
other++;
}
}
cout << "大写字母:" << upper << endl;
cout << "小写字母:" << lower << endl;
cout << "数字:" << digit << endl;
cout << "空格:" << space << endl;
cout << "其他字符:" << other << endl;
return 0;
}
```
阅读全文