1 solutions

  • 0
    @ 2024-5-23 17:06:49

    一道很好的结构体训练题 然后开始写cmp函数

    #include<bits/stdc++.h>
    #define int long long 
    # define gc() (iS==iT && (iT=(iS=ibuf)+fread(ibuf,1,SIZE,stdin),iS==iT)?EOF:*iS++)
    # define pc(c) ((oT==oS+SIZE && flush()),*oT++=(c))
    using std::cin;
    using std::cout;
    using std::endl;
    using std::cin;
    using std::ios;
    using std::sort;
    const int N=1e5;
    const int SIZE=(1<<21)+1;
    char ibuf[SIZE],obuf[SIZE],*iS,*iT,*oS=obuf,*oT=obuf;
    char* flush(){fwrite(obuf,1,oT-oS,stdout);return oT=obuf;}
    struct Flusher{~Flusher(){flush();}}flusher;
    template<typename T=int>
    T read()
    {
    	T x=0;
    	char ch=gc();
    	for(;ch<'0' || ch>'9';ch=gc());
    	for(;ch>='0' && ch<='9';ch=gc()) x=x*10+(ch-'0');
    	return x;
    }
    template<typename T>
    void write(T x)
    {
    	if(x>=10) write(x/10);
    	pc(x%10+'0');
    }
    struct shy{
    	int id;
    	int c,m,e;
    	int sm;
    	
    }x[N];
    bool cmp(shy a,shy b){
    	if(a.sm>b.sm)
    	return true;
    	else if(a.sm<b.sm)
    	return false;
    	else{
    		if(a.c>b.c) 
    		return true;
    		else if(a.c<b.c)
    		return false;
    		 else{
    		 	if(a.id>b.id){
    				return false;
    			 }else{
    			 	return true;
    			 }
    		 }
    	}
    		
    }
    signed main(void){
    	ios::sync_with_stdio(false);
    	cin.tie(nullptr);
    	int n;
    	cin>>n;
    	for(int i=1;i<=n;i++){
    		cin>>x[i].c>>x[i].m>>x[i].e;
    		x[i].id=i;
    		x[i].sm=x[i].c+x[i].m+x[i].e;
    	}
    	sort(x+1,x+1+n,cmp);
    	for(int i=1;i<=5;i++){
    		cout<<x[i].id<<" "<<x[i].sm<<endl;
    	}
    	return 0;
    }
    

    Information

    ID
    486
    Time
    1000ms
    Memory
    256MiB
    Difficulty
    10
    Tags
    # Submissions
    3
    Accepted
    3
    Uploaded By