hdoj-1004-Let the Balloon Rise(map排序)
生活随笔
收集整理的這篇文章主要介紹了
hdoj-1004-Let the Balloon Rise(map排序)
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
map按照value排序
1 #include <iostream> 2 #include <algorithm> 3 #include <cstring> 4 #include <map> 5 #include <vector> 6 #include <utility> 7 using namespace std; 8 typedef pair<string, int> PAIR; 9 bool cmp_by_value(const PAIR& lhs, const PAIR& rhs) { 10 return lhs.second > rhs.second; 11 } 12 map<string ,int> ship; 13 int main() { 14 int n; 15 while (cin>>n, n) { 16 ship.clear(); 17 for (int i=0; i<n; i++) { 18 string tmp; 19 cin>>tmp; 20 ship[tmp]++; 21 } 22 vector<PAIR> vec(ship.begin(), ship.end()); 23 sort(vec.begin(), vec.end(), cmp_by_value); 24 cout<<vec.begin()->first<<endl; 25 } 26 return 0; 27 }?
轉載于:https://www.cnblogs.com/evidd/p/8984226.html
總結
以上是生活随笔為你收集整理的hdoj-1004-Let the Balloon Rise(map排序)的全部內容,希望文章能夠幫你解決所遇到的問題。