题解 | #字符的个数#
字符的个数
https://www.nowcoder.com/practice/dc28f2bf113a4058be888a5875206238
#include <iostream> #include <bits/stdc++.h> #include <string> #include <map> using namespace std; int main() { string s; cin >> s; // write your code here...... string::iterator itr; map<char, int> m; for (itr = s.begin(); itr != s.end(); ++itr) { if (*itr == 'a') { m[*itr]++; } else if (*itr == 'b') { m[*itr]++; } else if (*itr == 'c') { m[*itr]++; } } for (map<char, int>::iterator itr = m.begin(); itr != m.end(); ++itr) { cout << itr->second << " "; } cout << endl; return 0; }