注意事项:map<char,int> mp; map的查找:mp.find(ch) ==mp.end()表示没找到,其他表示找到 map的插入:mp.insert(pair<char,int> m) map的输出:for(auto m:mp) m.first、m.second
// write your code here......
#include<map>
using namespace std;
int main() {
char str[100] = { 0 };
cin.getline(str, sizeof(str));
// write your code here......
map<char,int> mp;
for(int i=0;str[i]!='\0';i++)
{
if(isalpha(str[i]))
{
if(mp.find(str[i])==mp.end())
mp.insert(pair<char,int>(str[i],1));
else
mp[str[i]]++;
}
}
for(auto m:mp)
cout<<m.first<<":"<<m.second<<endl;
return 0;
}

京公网安备 11010502036488号