添加链接描述 1.要注意cmp要return (太粗了 2.v.size()-1是什么鬼 3.不同分数的话tot更新为i而不是++
#include <bits/stdc++.h>
using namespace std;
int n, k;
struct node1{
string name;
int score;
};
typedef pair<string,int> pii;
struct node{
string name;
int num,score,localrank;
};
bool cmp(node1 a,node1 b){
if(a.score==b.score)return a.name<b.name;
else return a.score>b.score;
}
bool cmp0(node a,node b){
if(a.score!=b.score)return a.score>b.score;
else return a.name<b.name;
}
vector<node> res;
int main()
{
cin >> n;
for(int j=1;j<=n;j++)
{
cin>>k;
vector<node1> v;
for (int i = 1; i <= k; i++)
{
string name;
int x;
cin >> name>>x;
v.push_back({name,x});
}
sort(v.begin(),v.end(),cmp);
res.push_back({v[0].name,j,v[0].score,1});
int now=v[0].score,tot=1;
for(int i=1;i<v.size();i++){
if(now!=v[i].score){
tot=i+1;
now=v[i].score;
}
res.push_back({v[i].name,j,v[i].score,tot});
}
}
cout<<res.size()<<endl;
sort(res.begin(),res.end(),cmp0);
cout<<res[0].name<<" 1 "<<res[0].num<<" 1"<<endl;
int now=res[0].score,tot=1;
for(int i=1;i<res.size();i++){
if(now!=res[i].score)now=res[i].score,tot=i+1;
cout<<res[i].name<<" "<<tot<<" "<<res[i].num<<" "<<res[i].localrank<<endl;
}
return 0;
}
|