曹孟德青梅煮酒
2022/2/26

曹孟德青梅煮酒

2021第三届浙江省高职院校新生联赛,属于是经典的结构体排序了

解法来讲并没有难的地方,但比赛的时候也是难道了我

程序代码如下:

                    
    #include<iostream>
    #include<algorithm>
    #include<cstring>
    #pragma GCC optimize(2)
    #define ll long long
    using namespace std;
    struct mate{
        string name;
        int F,IQ;
    }a[1008];
    int cmpF(mate a, mate b){
        if(a.F == b.F){
            if(a.IQ == b.IQ){
                return a.name < b.name;
            }else{
                return a.IQ > b.IQ;
                }
        }else{
            return a.F > b.F;
        }
    }
    int cmpIQ(mate a, mate b){
        if(a.IQ == b.IQ){
            if(a.F == b.F){
                return a.name < b.name;
            }else{
                return a.F > b.F;
            }

        }else{
            return a.IQ > b.IQ;
        }
    }
    int main(){
        ll n, ans = 1;
        while(cin >> n){
            ans = 1;
            for(int i = 1;i <= n;i++){
                cin >> a[i].name >> a[i].F >> a[i].IQ;
            }
            sort(a + 1,a + n + 1,cmpF);
            for(int i = 1;i<=n;i++){
                if(a[i - 1].F == a[i].F && a[i - 1].IQ == a[i].IQ /*&& i < n*/){
                    cout << ans << " " << a[i].name << " " << a[i].F << " " << a[i].IQ << endl;
                }else{
                    ans = i;
                    cout << ans << " " << a[i].name << " " << a[i].F << " " << a[i].IQ << endl;
                }
            }
            cout << "\n";
            sort(a + 1,a + n + 1,cmpIQ);
            ans = 1;
            for(int i = 1;i<=n;i++){
                if(a[i - 1].IQ == a[i].IQ && a[i - 1].F == a[i].F /*&& i < n*/){
                    cout << ans << " " << a[i].name << " " << a[i].F << " " << a[i].IQ << endl;
                }else{
                            ans = i;
                    cout << ans << " " << a[i].name << " " << a[i].F << " " << a[i].IQ << endl;
                }
            }
        }

    }
                
                

写完感觉自己灵魂都要被抽走了,但真的AC过后感觉心情非常的愉悦

可惜自己学业不精没能参加第一市赛

以后加油吧!继续努力!

Copyright © 2022 All Rights Reserved