L1-079 天梯赛的善良 分数 20

获取map的第一个和最后一个元素,分别使用begin()和-- end()访问。

// 9'21"
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin >> n;
    map<int,int> hash;
    for(int i = 1; i <= n; ++ i)
    {
        int tmp;
        cin >> tmp;
        hash[tmp] ++;
    }
    auto hi = hash.begin();
    cout << hi->first << " " << hi->second << endl;
    hi = -- hash.end();
    cout << hi->first << " " << hi->second << endl;
    return 0;
}
posted @ 2024-08-19 22:01  Frodnx  阅读(15)  评论(0)    收藏  举报