描述输入一串小写字母以‘’为结束标志统计出每个字母在该字符串中出现的次数若某字母不出现则不要输出。 要求:每行输出5项每项以空格隔开。用c++做输入描述输入一行以’结束的字符串输出描述输出相应小写字母的个数。用例输入 1 aaaabbbccc用例输出 1 a4 b3 c3
#include <iostream>
#include <unordered_map>
using namespace std;
int main() {
string s;
cin >> s;
unordered_map<char, int> count;
for (char c : s) {
if (c == '.') {
break;
}
count[c]++;
}
int cnt = 0;
for (auto p : count) {
cout << p.first << ":" << p.second << " ";
cnt++;
if (cnt % 5 == 0) {
cout << endl;
}
}
cout << endl;
return 0;
}
原文地址: https://www.cveoy.top/t/topic/jaap 著作权归作者所有。请勿转载和采集!