文章

8

粉丝

0

获赞

73

访问

1.1k

头像
成绩排序 题解:
P1151 清华大学上机题
发布于2026年3月17日 16:32
阅读数 134

#include <bits/stdc++.h>
using namespace std;

int main()
{
    int n,type;//个数,排序方法
    while(cin>>n>>type){
        multimap<int,string> mmap;//key值可以相同
        string a;//姓名
        int b;//成绩
        while(n--){
            cin>>a>>b;
            int k=(type==0) ? -b :b;
            mmap.emplace(k,a);
        }
        for(auto &it:mmap)
            cout<<it.second<<' '<<(type==0 ? -it.first:it.first)<<endl;

    }
    return 0;
}

 

登录查看完整内容


登录后发布评论

暂无评论,来抢沙发