20 pts求调
查看原帖
20 pts求调
961351
nightwatch.ryan楼主2024/8/30 14:04
#include<bits/stdc++.h>
#define int long long
using namespace std;

#define P(i, a, b) for(int i = a; i <= b; i++)
#define Q(i, a, b) for(int i = a; i >= b; i--)
const int maxn = 105;
const int inf = 0x3f3f3f3f;

mt19937 rnd(chrono::duration_cast<chrono::nanoseconds>
           (chrono::system_clock::now().time_since_epoch()).count());
int randint(int L, int R) {
    uniform_int_distribution<int> dist(L, R);
    return dist(rnd);
}

int n;

vector<vector<string>> item;
signed main(){

    cin.tie(0)->sync_with_stdio(0);
    cin >> n;
    string header, temp;
    cin >> header;
    vector<string> p;
    for(int i = 0; i < header.size(); i ++)
        if(header[i] == ',') p.push_back(temp), temp = "";
        else temp += header[i];
    if(temp != "") p.push_back(temp), temp = "";
    map<string, int> mp;
    for(int i = 0; i < p.size(); i ++){
        mp[p[i]] = i;
    }

    P(i, 1, n - 1){
        string mess, Temp;
        cin >> mess;
        vector<string> q;
        for(int j = 0; j < mess.size(); j ++)
            if(mess[j] == ',') q.push_back(Temp), Temp = "";
            else Temp += mess[j];
        if(Temp != "") q.push_back(Temp), Temp = "";
        item.push_back(q);
    }
    int m;
    cin >> m;
    P(i, 1, m){
        string x;
        cin >> x;
        char op = x.back();
        x.pop_back();
        int id = mp[x];
        string chk = item[0][id];
        bool type = 1; // 0: string 1: number
        for(auto i : chk)
            if(!isdigit(i))
                type = 0;
        if(op == '+')
            if(type) sort(item.begin(), item.end(), [id](vector<string> x, vector<string> y){return stoi(x[id]) < stoi(y[id]);});
            else sort(item.begin(), item.end(), [id](vector<string> x, vector<string> y){return x[id] < y[id];});
        else
            if(type) sort(item.begin(), item.end(), [id](vector<string> x, vector<string> y){return stoi(x[id]) > stoi(y[id]);});
            else sort(item.begin(), item.end(), [id](vector<string> x, vector<string> y){return x[id] > y[id];});
    }
    cout << header << endl;
    for(auto it : item){
        cout << it[0];
        for(int i = 1; i < it.size(); i ++){
            cout << "," << it[i];
        }
        cout << endl;
    }
}
2024/8/30 14:04
加载中...