1. 程式人生 > >第十一章 關聯容器

第十一章 關聯容器

count ace 關聯 mic mil const ret sin .com

使用關聯容器

使用set

 1 #include<iostream>
 2 #include<string>
 3 #include<map>
 4 
 5 using namespace std;
 6 
 7 int main()
 8 {
 9     map<string, size_t> word_count;
10     string word;
11     while (cin >> word)
12         ++word_count[word];
13     for (const auto &w : word_count)
14 cout << w.first << " 出現 " << w.second 15 << ((w.second > 1) ? "times" : "time") << endl; 16 return 0; 17 }

運行結果:
技術分享圖片

使用set



第十一章 關聯容器