基本思想:
没什么难的,水题,重点在于审题;
关键点:
无;
#include<iostream> #include<stdlib.h> #include<stdio.h> #include<vector> #include<string> #include<math.h> #include<algorithm> #include<cstring> using namespace std; using std::vector; const int maxn = 10010; int n, c; struct member { string name; int id; int grade; }; vector<member>vec; bool cmp(member a, member b) { if (c == 1) { return a.id < b.id; } else if (c == 2) { if (strcmp(a.name.c_str(), b.name.c_str()) < 0) return true; else if (strcmp(a.name.c_str(), b.name.c_str()) == 0) return a.id < b.id; else return false; } else { if (a.grade == b.grade) return a.id < b.id; else return a.grade < b.grade; } } int main() { scanf("%d %d", &n, &c); vec.resize(n); for (int i = 0; i < n; i++) { cin >> vec[i].id >> vec[i].name >> vec[i].grade; } sort(vec.begin(), vec.end(), cmp); for (int i = 0; i < n; i++) { printf("%06d %s %d\n", vec[i].id, vec[i].name.c_str(), vec[i].grade); } system("pause"); return 0; }