#include <iostream>
#include <string.h>
#include <vector>
#include <algorithm>
typedef long long ll;
using namespace std;
typedef struct people
{
int pass=0,time=0;
char name[21];
int flag[16]={0};//这道题对了没
}p;
bool cmp(struct people a,struct people b)
{
if (a.pass!=b.pass) return a.pass>b.pass;
if (a.time!=b.time) return a.time<b.time;
}
int main()
{
vector <p> v;
int time;
while(scanf("%d",&time)!=EOF)
{
char name[21];
char title;
int res;
cin>>name;
getchar();
cin>>title>>res;
int index=-1;
for(int i=0;i<v.size();i++)
{
if (strcmp(v[i].name,name)==0)
{
index=i;
break;
}
}
if (index==-1)
{
p t;
strcpy(t.name,name);
index=v.size();
v.push_back(t);
}
if (!res && v[index].flag[title-'A']!=-1)
{
v[index].pass++;
v[index].time+=v[index].flag[title-'A'];
v[index].time+=time;
v[index].flag[title-'A']=-1;//表示已经对了
}
else if (res)
v[index].flag[title-'A']+=20;
}
sort(v.begin(),v.end(),cmp);
for(int i=0;i<v.size();i++)
{
if (v[i].pass)
{
printf("%s %d %d\n",v[i].name,v[i].pass,v[i].time);
}
}
}
解法二
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
struct people
{
int time=0,pass=0;
int title[16]={0};
string name;
bool operator <(people a)const
{
if (a.pass!=pass)
return a.pass<pass;
else return a.time>time;
}
};
int main()
{
int now;
vector <people> v;
while(scanf("%d",&now)!=EOF)
{
string name;
char ch;
int result;
getchar();
cin>>name>>ch>>result;
bool flag=false;
int index=v.size();
for(int i=0;i<v.size();i++)
{
if (name==v[i].name)
{
flag=true;
index=i;
break;
}
}
if (!flag)
{
people t;
t.name=name;
v.push_back(t);
}
if (result!=0)
{
v[index].title[ch-'A']+=20;
}
else if (result==0)
{
if (v[index].title[ch-'A']!=-1)
{
v[index].time+=now+v[index].title[ch-'A'];
v[index].title[ch-'A']=-1;
v[index].pass++;
}
}
}
sort(v.begin(),v.end());
for(int i=0;i<v.size();i++)
{
if (v[i].pass==0)
break;
cout<<v[i].name<<" ";
printf("%d %d\n",v[i].pass,v[i].time);
}
}