hdu 2093 成绩排名

在这里插入图片描述

思路:

没啥思路,就是定义结构体,跟题目,走,当时没想到对那个括号的处理,后面看了题解,才知道用个getchar直接判断
算是一个值得思考的点。

代码:

#include<bits/stdc++.h>
using namespace std;
struct node{
	char name[10];
	int ac;
	int time;
	 
};
bool cmp(node a,node b)
{
	if(a.ac!=b.ac)
	{
		return a.ac>b.ac;
	}else
	{
		if(a.time!=b.time)
		{
			return a.time<b.time;
		}else
		{
			return a.name<b.name;
		}
	}
} 


int main()
{
	int n,m;
	int t=6;
	vector<node> res;
	char temp[10];
	int tmp;
	cin>>n>>m;
	while(~scanf("%s",temp))
	{
		node p1;
		strcpy(p1.name,temp);
		p1.ac=p1.time=0;
		for(int i=0;i<n;i++)
		{
			scanf("%d",&tmp);
			char c=getchar();
			if(tmp>0)
			{
				p1.ac++;
				p1.time+=tmp;
				if(c=='(')
				{
					scanf("%d",&tmp);
					p1.time+=tmp*m;
					getchar();
				}
			}
			
		}
		res.push_back(p1);
	}
	sort(res.begin(),res.end(),cmp);
	for(int i=0;i<res.size();i++)
	{
		printf("%-10s %2d %4d
",res[i].name,res[i].ac,res[i].time);
	}
	

} 
原文地址:https://www.cnblogs.com/YenKoc/p/12779929.html