#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
using namespace std;
struct stu
{
string name;
int grade;
};
bool studes(stu a, stu b)
{
return a.grade > b.grade;
}
bool stuAcs(stu a, stu b)
{
return a.grade < b.grade;
}
int main()
{
int n;
int flag;
cin >> n >> flag;
vector<stu>student;
student.resize(n);
for (int i = 0; i < n; i++)
{
cin >> student[i].name >> student[i].grade;
}
if (flag)
{
sort(student.begin(), student.end(), stuAcs);
}
else
sort(student.begin(), student.end(), studes);
for (int i = 0; i < n; i++)
{
cout << student[i].name << " " << student[i].grade << endl;
}
system("pause");
return 0;
#include<vector>
#include<string>
#include<algorithm>
using namespace std;
struct stu
{
string name;
int grade;
};
bool studes(stu a, stu b)
{
return a.grade > b.grade;
}
bool stuAcs(stu a, stu b)
{
return a.grade < b.grade;
}
int main()
{
int n;
int flag;
cin >> n >> flag;
vector<stu>student;
student.resize(n);
for (int i = 0; i < n; i++)
{
cin >> student[i].name >> student[i].grade;
}
if (flag)
{
sort(student.begin(), student.end(), stuAcs);
}
else
sort(student.begin(), student.end(), studes);
for (int i = 0; i < n; i++)
{
cout << student[i].name << " " << student[i].grade << endl;
}
system("pause");
return 0;
}