女赛--Solving Order

题意:根据权值从大到小排序,依次输出字符串
思路:水题,超级简单,一个结构体,一个结构体的小于判别
#include<cstdio>
#include<cstring>
#include<cmath>
#include<iostream>
#include<queue>
#include<algorithm>
using namespace std;
int n,T,x,num;
char ch[50];
struct AA
{
    string s;
    int x;
}pos[50];
bool cmp(AA aa,AA bb)
{
    return aa.x>bb.x;
}
int main()
{
    scanf("%d",&T);
    while(T--)
    {
        num=0;
        scanf("%d",&n);
        for(int i=1;i<=n;i++)
        {
            scanf("%s%d",ch,&x);
            pos[i].s=ch;
            pos[i].x=x;
        }
        sort(pos+1,pos+n+1,cmp);
        for(int i=1;i<n;i++)
        {
            cout<<pos[i].s<<" ";
        }
        cout<<pos[n].s<<endl;
    }
}

代码:

猜你喜欢

转载自blog.csdn.net/qq_37868325/article/details/80274692