标签:node namespace else using eve printf pre vector i++
模拟水题。
#include<bits/stdc++.h>
using namespace std;
struct node
{
string name;
int final_rank,loc_num,loc_rank,grade;
node(string name,int loc_num,int grade)
{
this->name=name;
this->loc_num=loc_num;
this->grade=grade;
}
void paixu(int flag,int w)
{
flag==0?loc_rank=w:final_rank=w;
}
bool operator <(const node &n) const
{
if(grade!=n.grade)
return grade>n.grade;
else
return name<n.name;
}
};
vector<node> v;
int k;
void paixu(int s,int e,int flag);
int main()
{
int i,j,n,grade,start=0;
string name;
scanf("%d",&n);
for(i=1;i<=n;i++)
{
scanf("%d",&k);
for(j=0;j<k;j++)
{
cin>>name>>grade;
v.push_back(node(name,i,grade));
}
sort(v.begin()+start,v.begin()+start+k);
paixu(start,start+k,0);
start+=k;
}
sort(v.begin(),v.end());
paixu(0,v.size(),1);
printf("%d\n",v.size());
for(i=0;i<v.size();i++)
printf("%s %d %d %d\n",v[i].name.c_str(),v[i].final_rank,v[i].loc_num,v[i].loc_rank);
system("pause");
return 0;
}
void paixu(int s,int e,int flag)
{
int i,pre_grade=-1,cnt=1,same=1;
for(i=s;i<e;i++)
{
if(v[i].grade!=pre_grade)
{
v[i].paixu(flag,cnt);
same=cnt;
}
else
{
v[i].paixu(flag,same);
}
cnt++;
pre_grade=v[i].grade;
}
}
PAT (Advanced Level) 1025 PAT Ranking
标签:node namespace else using eve printf pre vector i++
原文地址:https://www.cnblogs.com/VividBinGo/p/12221298.html