1028 List Sorting (25point(s)) Easy only once
Posted songlinxuan
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了1028 List Sorting (25point(s)) Easy only once相关的知识,希望对你有一定的参考价值。
基本思想:
没什么难的,水题,重点在于审题;
关键点:
无;
#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 ", vec[i].id, vec[i].name.c_str(), vec[i].grade); } system("pause"); return 0; }
以上是关于1028 List Sorting (25point(s)) Easy only once的主要内容,如果未能解决你的问题,请参考以下文章
PAT 甲级 1028 List Sorting (25 分)(排序,简单题)
PAT Advanced 1028 List Sorting (25分)