问题标题: 酷丁编程:995

1
0
已解决
查宣乔
查宣乔
初级守护
初级守护

题目链接: 酷丁编程:2703

#include<bits/stdc++.h>
using namespace std;
struct t{
    int x,t;  
}a[50005];
bool cmp(t a,t b){
if(a.x==b.x)
return a.t<b.t;
return a.x>b.x;
}
int main(){
    int n,cnt=0;
    cin>>n;
    for(int i=1;i<=n;i++){
        cin>>a[i].t;
        a[i].x=i;
    }
    sort(a+1,a+n+1,cmp);
    for(int i=1;i<=n;i++){
        cout<<a[i].x<<" ";
        cnt++;
        if(cnt==2){
        cout<<endl;
        cnt=0;
        }
    }

    return 0;
}

0
已采纳
许晏恺
许晏恺
新手光能
新手光能

结构体排序实现

struct stu{
    int id,point;
}a[1005];
bool cmp(stu x,stu y){
    if(x.point==y.point) return x.id<y.id;
    return x.point>y.point;
}

附上自己写的部分代码+学习视频C++结构体介绍 5分钟左右

(话说好久都没看到问题目的啊)

我要回答