1 条题解
-
0
码量一般的模拟。
把表头和学生信息以
,
为分隔符拎出来,存起来。由于(据我所知)不同类型数组不能开在一起,所以信息存的是 个内容,分别表示为数还是字符串,以及数字的值和字符串的值。排序部分,把排序方式先离线下来。比较两个元素时,按顺序遍历排序方式,判断升序降序,为数还是字符串,然后进行比较。
由于给定排序方法相同需要按照原顺序,所以多加一个 用来判断全部一样时的先后顺序。
#include <bits/stdc++.h> using namespace std; int n, m, c; string s, t; int cnt; string cmp[20]; string tt; map<string, int> title; struct node { bool op; // int 0 str 1 int x; string y; }; vector<node> a[120]; bool isstr(string s) { int cnt = 0; for (char c : s) if (isdigit(c)) cnt++; return cnt < s.size(); } bool ccmp(vector<node> a, vector<node> b) { for (int i = 1; i <= c; i++) { int op = cmp[i].back(); string t = cmp[i].substr(0, cmp[i].size() - 1); int j = title[t]; if (op == '+') { if (!a[j].op) { if (a[j].x == b[j].x) continue; return a[j].x < b[j].x; } else { if (a[j].y == b[j].y) continue; return a[j].y < b[j].y; } } else { if (!a[j].op) { if (a[j].x == b[j].x) continue; return a[j].x > b[j].x; } else { if (a[j].y == b[j].y) continue; return a[j].y > b[j].y; } } } return a[0].x < b[0].x; } int main() { cin >> n >> s; tt = s; s += ','; for (int i = 0; i < s.size(); i++) { if (s[i] == ',') { title[t] = ++m; t = ""; continue; } t += s[i]; } for (int i = 1; i < n; i++) { a[i].resize(m + 20); cin >> s; s += ','; t = ""; a[i][0].x = i; int cnt = 0; for (int j = 0; j < s.size(); j++) { if (s[j] == ',') { cnt++; a[i][cnt].op = isstr(t); if (!a[i][cnt].op) a[i][cnt].x = stoi(t); else a[i][cnt].y = t; t = ""; continue; } t += s[j]; } } cin >> c; for (int i = 1; i <= c; i++) cin >> cmp[i]; sort(a + 1, a + n, ccmp); cout << tt << '\n'; for (int i = 1; i < n; i++) { for (int j = 1; j <= m; j++) { if (!a[i][j].op) cout << a[i][j].x; else cout << a[i][j].y; putchar(j == m ? '\n' : ','); } } return 0; }
- 1
信息
- ID
- 960
- 时间
- 1000ms
- 内存
- 256MiB
- 难度
- 3
- 标签
- 递交数
- 13
- 已通过
- 11
- 上传者