Zjut 1330 竞赛排名 请你查错

本文深入探讨了排序算法和数据结构的应用,包括常见的排序算法(如快速排序、归并排序)及其复杂度分析,以及数据结构(如二叉树、链表、哈希表)在实际场景中的实现和优化策略。
//http://acm.zjut.edu.cn/ShowProblem.aspx?ShowID=1330
#include<iostream>
#include
<string>
#include
<vector>
#include
<algorithm>
usingnamespacestd;

structPlayer
...{
stringname;
intscore;
}
;

vector
<Player>v;

intfindName(stringname)
...{
for(inti=0;i<v.size();i++)
if(v[i].name==name)returni;
return-1;
}


boolcmp(Playera,Playerb)
...{
if(a.score==b.score)
returna.name<b.name;
else
returna.score>b.score;
}


voidaddPlayer(stringname,intscore)
...{
Playert;
t.name
=name;
t.score
=score;
v.push_back(t);
}


voidoutputPlayer()
...{
cout
<<1<<":"<<v[0].name;
for(inti=1;i<v.size();i++)
...{
if(v[i].score==v[i-1].score)
...{
cout
<<""<<v[i].name;
}

else
...{
cout
<<endl;
cout
<<i+1<<":"<<v[i].name;
}

}

cout
<<endl;
}


boolrun(intnow)
...{
intn;
cin
>>n;
if(n==0)returnfalse;
v.clear();

inti,m=n*(n-1)/2;

for(i=0;i<m;i++)
...{
strings,t;
boolf;

cin
>>s>>t>>f;
intj=findName(s);
intk=findName(t);

if(f==true)
...{
if(j==-1)
addPlayer(s,
3);
else
v[j].score
+=3;

if(k==-1)addPlayer(t,0);
}

else
...{
if(j==-1)
addPlayer(s,
1);
else
v[j].score
++;

if(k==-1)
addPlayer(t,
1);
else
v[k].score
++;
}

}


if(n>=2)
...{
sort(v.begin(),v.end(),cmp);
outputPlayer();
}


returntrue;
}


intmain()
...{
intnow=1;
while(run(now++));
return0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值