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

查看22道真题和解析