字符计数
字符计数题目描述
输入一个由大写字母、小写字母和数字组成的字符串,统计里面有多少个大写字母、小写字母和数字。
输入:一行字符串
输出:3 个数,分别代表字符串中大写字母、小写字母和数字出现的次数。
我的解答
// 字符串计数问题
#include <iostream>
#include <string>
using namespace std;
int main()
{
int a = 0, b = 0, c = 0, i = 0;
string s;
cin >> s;
for (; i < s.length(); i++)
{
if ('A' <= s && s <= 'Z')
a++;
else if ('a' <= s && s <= 'z')
b++;
else
c++;
}
cout << a << " " << b << " " << c;
return 0;
}
页:
[1]