CF19A World Football Cup(被输入输出恶心到了)

写在前面:

本题中的关键点:

【1】积分榜是按照以下原则制作的:胜利一个队得3分,平分1分,失败0分。首先,球队按积分顺序排在积分榜上,分数相等比较净胜球,净胜球相等比较进球数

【2】按照字典顺序输出n/2n/2行进入淘汰赛阶段的球队的名字

【3】输入时的'-'与':'的处理

净胜球】:是指进球数与失球数的差

 原题复刻:

想法与思路:一道模拟题加sort排序,难点在于审清题意以及对输入数据的正确处理。

个人对于'-'的处理:

       string tempa,tempb,tempfu;

        cin>>tempfu;
        tempa=tempfu.substr(0,tempfu.find('-'));
        tempb=tempfu.substr(tempfu.find('-')+1); 

//不加注释了
#include<bits/stdc++.h>
using namespace std;
const int mod=1e9+7;
const int MAX=1e6+10;
typedef long long ll;
long long n;
map<string,int>fen,jinshen,jinqiu;
struct dui
{
    string name;
    int fen,jinshen,jingqiu;

}dui[MAX];
bool cmp1(struct dui a,struct dui b)
{
    if(a.fen!=b.fen)return a.fen>b.fen;
    else
    {
        if(a.jinshen!=b.jinshen)return a.jinshen>b.jinshen;
        else return a.jingqiu>b.jingqiu;

    }

}
bool cmp2(struct dui a,struct dui b)
{
    return a.name<b.name;

}
void input()
{
    cin>>n;
    for(int i=1; i<=n; i++)
    {
        string temp;
        cin>>temp;
        fen[temp]=0;
    }
    ll temp=n*(n-1)/2;
    string tempa,tempb,tempfu;
    while(temp--)
    {
        cin>>tempfu;
        tempa=tempfu.substr(0,tempfu.find('-'));
        tempb=tempfu.substr(tempfu.find('-')+1);
        int ji1,ji2;
        char c;
        cin>>ji1>>c>>ji2;
        if(ji1==ji2)
        {
            fen[tempa]++;
            fen[tempb]++;
        }
        else if(ji1>ji2)fen[tempa]+=3;
        else fen[tempb]+=3;
        jinshen[tempa]+=ji1-ji2;
        jinshen[tempb]+=ji2-ji1;
        jinqiu[tempa]+=ji1;
        jinqiu[tempb]+=ji2;
    }


}
void solve()
{
    map<string,int>::iterator it=fen.begin();
    for(int i=1; i<=n; i++,it++)
    {
        dui[i].name=it->first;
        dui[i].fen=fen[it->first];
        dui[i].jingqiu=jinqiu[it->first];
        dui[i].jinshen=jinshen[it->first];
    }
    sort(dui+1,dui+1+n,cmp1);
    sort(dui+1,dui+1+n/2,cmp2);
    for(int i=1; i<=n/2; i++)cout<<dui[i].name<<endl;
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t=1;
    //cin>>t;
    while(t--)
    {
        input();
        solve();
    }

}














  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值