RC-u1-2023【struct sort】

Raicom-2023省赛题目~

题意:

2022 年第 19 届亚运会即将在杭州召开,杭州已经做好准备欢迎全亚洲的观众一同参与亚运盛会了!

你正在开发一款跟亚运奖牌计算相关的 App。给定两个国家的获奖情况,你的任务是计算这两个国家/地区的奖牌情况,并确定哪个国家/地区要排在奖牌榜的前面。

输入格式:

输入第一行是一个正整数 N (1≤N≤1000),表示总共有 N 条获奖记录。

接下来的每一行都是形如以下的一条记录:

Ci​,Pi​

其中 Ci​=0,1,0 表示是第一个国家/地区,1 表示是第二个国家/地区;Pi​=1,2,3,1 表示金牌,2 表示银牌,3 表示铜牌。

输出格式:

首先输出两行,第一行是第一个国家/地区的金牌、银牌、铜牌获得数,用空格隔开;第二行是第二个国家/地区的奖牌获奖情况,要求与格式同第一个国家/地区。

最后一行,如果是第一个国家/地区排在前面,输出 The first win!,否则输出 The second win!

排在前面的定义是:先比较金牌数,金牌数较大的排在前面;如金牌数相等,比较银牌数,银牌数较大的在前面;如金牌银牌数都相等,则比较铜牌数,铜牌数较大的在前面。

保证数据不存在奖牌数完全相同的情况。

输入样例:

15
0 1
0 2
0 3
0 1
0 1
0 2
0 3
1 3
1 3
1 3
1 3
1 2
1 1
1 1
1 1

输出样例:

3 2 2
3 1 4
The first win!

代码【C++】: 

# include<bits/stdc++.h>
using namespace std;
struct duiwu{// 记录每个队伍的国家/地区、金银牌奖个数
    int id;
    int au;
    int ag;
    int cu;
}country[2];
void init(){// 初始化结构体
    country[0].id=0;
    country[0].au=0;
    country[0].ag=0;
    country[0].cu=0;
    country[1].id=1;
    country[1].au=0;
    country[1].ag=0;
    country[1].cu=0;
}
bool cmp(struct duiwu a,struct duiwu b){
    if(a.au!=b.au) return a.au>b.au;
    else if(a.ag!=b.ag) return a.ag>b.ag;
    else return a.cu>b.cu;
}
int main(){
    init();
    int n;
    cin>>n;
    int temp_id,temp_goal;
    while(n--){
        cin>>temp_id>>temp_goal;
        if(temp_goal==1){
            country[temp_id].au++;
        }else if(temp_goal==2){
            country[temp_id].ag++;
        }else{
            country[temp_id].cu++;
        }
    }
    sort(country,country+2,cmp);
    int first=0;//标识第一个国家当前的下标
    if(country[0].id==1){//第二个国家排第一
        first=1;
    }
    cout<<country[first].au<<" "<<country[first].ag<<" "<<country[first].cu<<endl;
    cout<<country[1-first].au<<" "<<country[1-first].ag<<" "<<country[1-first].cu<<endl;
    if(first==0) cout<<"The first win!"<<endl;
    else cout<<"The second win!"<<endl;
    return 0;
}

  • 8
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值