get一个超级厉害的统计字符串个数的算法(可能是我见识短)

 1 #include <iostream>
 2 #include <string>
 3 #include <set>
 4 #include <map>
 5 
 6 using namespace std;
 7 
 8 //统计字符串中每个字符出现的次数
 9 
10 int main()
11 {
12     string s;
13     cin >> s;
14 
15     map<char, int> m;
16 
17     for (auto & i : s)
18     {
19         m[i]++;
20     }
21 
22     for (auto & i : m)
23     {
24         cout << i.first << ' ' << i.second << endl;
25     }
26 
27     system("pause");
28         return 0;
29 }

这是运行截图,用了都说好!

真的好绝一代码,不过我目前还没有研究每个语句的作用,还是要查找资料看看

猜你喜欢

转载自www.cnblogs.com/2019-12-10-18ykx/p/12898245.html
今日推荐