下面是代码:
#include <bits/stdc++.h>
using namespace std;
struct student
{
int no;
double score;
} stu[101];
bool operator<(student a, student b)
{
return a.score > b.score;
}
int main()
{
int n, k;
cin >> n >> k;
for (int i=0; i<n; i++)
cin >> stu[i].no >> stu[i].score;
stable_sort(stu, stu+n);
cout << stu[k-1].no << " " << stu[k-1].score << endl;
return 0;
}
下面是代码:
#include <bits/stdc++.h>
using namespace std;
int main()
{
int n,i,a[500];
while(~scanf("%d",&n))
{
for(i=1;i<=n;i++)
scanf("%d",&a[i]);
sort(a+1,a+n+1);
for(i=1;i<=n;i++)
{
if(a[i]%2==1)
{
if(i==1)printf("%d",a[i]);
else printf(",%d",a[i]);
}
}
printf("\n");
}
return 0;
}