题解
2023-08-24 14:15:12
发布于:广东
15阅读
0回复
0点赞
#include <bits/stdc++.h>
using namespace std;
vector<pair<int, int>> f(int n, vector<int>& nums) {
map<int, int> counts;
for (int i = 0; i < n; i++) {
counts[nums[i]]++;
}
vector<pair<int, int>> a(counts.begin(), counts.end());
sort(a.begin(), a.end(), [](const pair<int, int>& a, const pair<int, int>& b) {
return a.first < b.first;
});
return a;
}
int main() {
int n;
cin >> n;
vector<int> nums(n);
for (int i = 0; i < n; i++) {
cin >> nums[i];
}
vector<pair<int, int>> result = f(n, nums);
for (const auto& p : result) {
cout << p.first << " " << p.second << endl;
}
return 0;
}
这里空空如也
有帮助,赞一个