题目意思就是一场比赛有多个赛区,你要分别求出每个人的赛区排名和总排名。排名要求成绩并列的排名相同,下一个排名为上一个排名的人数+1.比如排第一的有两个人,那么第三个人的排名是3而不是2。
用结构体处理,水题,但是有点小麻烦,详见代码~
#include <iostream> #include <string.h> #include <cstdio> #include <algorithm> #include <cstdlib> #include <math.h> #include <queue> #include <stack> #include <vector> #include <unordered_map> #define maxn 1005 #define INF 0x3f3f3f3f using namespace std; typedef long long ll; struct Student { string name; int score,lrank,frank,lnum; }stu[maxn],ts[maxn]; int n,k,p; bool tcmp(Student a,Student b) { return a.score>b.score; } bool cmp(Student a,Student b) { if(a.score==b.score) return a.name<b.name; return a.score>b.score; } int main() { ios::sync_with_stdio(false); cin>>n; p=0; for(int ln=1;ln<=n;ln++) { cin>>k; for(int i=0;i<k;i++) cin>>ts[i].name>>ts[i].score; sort(ts,ts+k,tcmp); int maxx=-1,tr=0; for(int i=0;i<k;i++) { stu[p].name=ts[i].name; stu[p].score=ts[i].score; stu[p].lnum=ln; if(maxx==ts[i].score) stu[p].lrank=tr; else { stu[p].lrank=i+1; tr=i+1; maxx=ts[i].score; } p++; } } sort(stu,stu+p,cmp); int maxx=-1,tr=0; for(int i=0;i<p;i++) { cout<<stu[i].name<<" "; if(maxx==stu[i].score) cout<<tr; else { cout<<i+1; tr=i+1; maxx=stu[i].score; } cout<<" "<<stu[i].lnum<<" "<<stu[i].lrank<<endl; } return 0; }