去年团体天梯赛的题目, 当时有一个点wa了,就没管了,今天突然想起来了,这道题就是一道语法题
题目
代码
#include <bits/stdc++.h>
using namespace std;
int n, m;
unordered_map<string, int> mp;
vector<pair<int, vector<int>>> ans;
int main() {
cin >> n >> m;
getchar();
for (int i = 1; i <= n; ++ i) {
string ve;
getline(cin, ve);
mp[ve] ++;
}
for (auto& [x, y] : mp) {
stringstream os(x);
vector<int> tm(m);
for (int i = 0; i < m; ++ i)
os >> tm[i];
ans.emplace_back(y, tm);
}
sort (ans.begin(), ans.end(), [](auto& a, auto& b) {
#define x first
#define y second
if (a.x == b.x) {
auto &x = a.y;
auto &y = b.y;
for (int i = 0; i < min (x.size(), y.size()); ++ i)
if (x[i] != y[i]) return x[i] < y[i];
return x.size() < y.size();
}
return a.x > b.x;
});
cout << ans.size() << endl;
for (auto& [x, y] : ans) {
cout << x;
for (auto& t : y)
cout << " " << t;
cout << endl;
}
return 0;
}
|