注意:这个题需要注意的是当分数相同时,输出需要按照序号从小到大输出
这道题用结构体也特别方便
#include<bits/stdc++.h>
using namespace std;
struct demo
{
int name;
int goal;
}emp[100000];
int main()
{
int n, m;
cin >> n >> m;
for (int i = 1; i <= n; i++)
{
cin >> emp[i].name >> emp[i].goal;
}
int p = floor(1.5 * m);
//信息按照成绩排序
for (int i = 1; i <= n; i++)
{
for (int j = 1; j <= n - i; j++)
{
if (emp[j].goal < emp[j + 1].goal)
{
demo t = emp[j];
emp[j] = emp[j + 1];
emp[j + 1] = t;
}
//id按照字典叙输出
if (emp[j].goal == emp[j + 1].goal)
{
if (emp[j].name > emp[j + 1].name)
{
demo tmp = emp[j];
emp[j] = emp[j + 1];
emp[j + 1] = tmp;
}
}
}
}
int cj = emp[p].goal;
int num = 0;
for (int i = 1; i <=n; i++)
{
if (emp[i].goal > cj || emp[i].goal == cj)
{
num++;
}
}
cout << cj << " " << num << endl;
for (int i = 1; i <=num; i++)
{
cout << emp[i].name << " " << emp[i].goal << endl;
}
}