Skip to content

Latest commit

 

History

History
98 lines (83 loc) · 1.48 KB

1028.md

File metadata and controls

98 lines (83 loc) · 1.48 KB

1028

Accepted

#include <iostream>
#include <algorithm>
#include <string>
using namespace std;

int N, C;
const int MAX_N = 1e5 + 5;
struct Student {
	string ID, name;
	int grade;
} s[MAX_N];

bool cmp1(Student s1, Student s2) {
	return s1.ID < s2.ID;
}

bool cmp2(Student s1, Student s2) {
	if (s1.name == s2.name) {
		return s1.ID < s2.ID;
	}
	return s1.name < s2.name;
}

bool cmp3(Student s1, Student s2) {
	if (s1.grade == s2.grade) {
		return s1.ID < s2.ID;
	}
	return s1.grade < s2.grade;
}

int main() {
	cin >> N >> C;
	for (int n = 0; n < N; n++) {
		cin >> s[n].ID >> s[n].name >> s[n].grade;
	}
	if (C == 1) {
		sort(s, s + N, cmp1);
	}
	else if (C == 2) {
		sort(s, s + N, cmp2);
	}
	else if (C == 3) {
		sort(s, s + N, cmp3);
	}
	for (int n = 0; n < N; n++) {
		cout << s[n].ID << " " << s[n].name << " " << s[n].grade << endl;
	}
}

/*
Sample Input 1:
3 1
000007 James 85
000010 Amy 90
000001 Zoe 60
Sample Output 1:
000001 Zoe 60
000007 James 85
000010 Amy 90

Sample Input 2:
4 2
000007 James 85
000010 Amy 90
000001 Zoe 60
000002 James 98
Sample Output 2:
000010 Amy 90
000002 James 98
000007 James 85
000001 Zoe 60

Sample Input 3:
4 3
000007 James 85
000010 Amy 90
000001 Zoe 60
000002 James 90
Sample Output 3:
000001 Zoe 60
000007 James 85
000002 James 90
000010 Amy 90
*/

References