题目描述:
解题思路:
- 使用map统计
- 遍历一次字符串
代码实现:
代码语言:javascript复制#include <string>
#include <map>
#include <iostream>
using namespace std;
void Count(const string& s) {
map<char, int> mp;
for (auto c : s) {
mp[c] ;
}
for (auto k: mp) {
cout << k.first << " : " << k.second << endl;
}
}
int main() {
cout << "please input a str:" << endl;
string s;
cin >> s;
(void)Count(s);
return 0;
}