基本思想:
弱智题,注意同名情况需要按照输入排序,加个标志位就可以了;
关键点:
牛课的oj还要循环测case,我佛了;
#include<iostream> #include<vector> #include<algorithm> #include<string> using namespace std; int n; int m; struct node { int a; string s; int time; }; bool cmp(node a,node b) { if (m == 0) { if (a.a != b.a) { return a.a > b.a; } else if (a.a == b.a) { return a.time < b.time; } } else { if (a.a != b.a) { return a.a < b.a; } else if (a.a == b.a) { return a.time < b.time; } } } vector<node>vec; int main() { while(cin >> n >> m){ vec.resize(0); for (int i = 0; i < n; i++) { node no; cin >> no.s >> no.a; no.time = i; vec.push_back(no); } sort(vec.begin(), vec.end(), cmp); for (auto ele : vec) { cout << ele.s << " " << ele.a << endl; } } return 0; }