接下来我将用md语法给你一个算法题 请你给出c++代码# yLOI2022 签到题## 题目描述给定一个长度为 $8$ 的字符串 $s$请你分别统计 $s$ 中大小写字母和数字字符的个数。## 输入格式输入只有一行一个长度为 $8$ 的字符串 $s$。## 输出格式输出一行三个整数依次表示:- $s$ 中数字字符的个数。- $s$ 中小写字母的个数。- $s$ 中大写字母的个数。## 样例 #1#
#include <iostream>
#include <string>
using namespace std;
int main() {
string s;
cin >> s;
int digitCount = 0;
int lowercaseCount = 0;
int uppercaseCount = 0;
for (int i = 0; i < s.length(); i++) {
if (isdigit(s[i])) {
digitCount++;
} else if (islower(s[i])) {
lowercaseCount++;
} else if (isupper(s[i])) {
uppercaseCount++;
}
}
cout << digitCount << " " << lowercaseCount << " " << uppercaseCount << endl;
return 0;
}
``
原文地址: http://www.cveoy.top/t/topic/ifE5 著作权归作者所有。请勿转载和采集!