百练2704 竞赛评分

描述
现举行一次小竞赛,参赛的3支队伍,编号为1,2,3.每支队列轮流回答问题,如果回答正确,加10分;回答错误,扣10分;放弃回答不得分.经过多轮答题后,我们要统计各队的名次和得分.
输入
第一行为回答问题的轮次数n.
其余各行分别为1,2,3号队伍答题的结果,回答正确为right,错误为wrong,放弃为give-up.
输出
按名次输出各队的编号和得分.名次相同的在同一行输出,且编号小者靠前.

样例输入
4
right wrong give-up
right right right
wrong right right
right right right
样例输出
(3,30)
(1,20)(2,20)

#include <iostream>
#include <string>
#include <algorithm>
#include <cstring>
using namespace std;
struct node
{
	int i;
	int score;
	int rank;
} Gro[3];
int change(string s)
{
	if (s == "right")
	{
		return 10;
	}
	else if (s == "wrong")
	{
		return -10;
	}
	else
	{
		return 0;
	}
}
bool cmp(node t, node s)
{
	return t.score > s.score;
}
int main()
{
	int n;
	cin >> n;
	while (n--)
	{
		string s;
		for (int i = 0; i < 3; i++)
		{
			cin >> s;
			Gro[i].i = i + 1;
			Gro[i].score += change(s);
		}
	}
	sort(Gro, Gro + 3, cmp);
	Gro[0].rank = 1;
	for (int i = 1; i < 3; i++)
	{
		if (Gro[i].score == Gro[i-1].score)
		{
			Gro[i].rank = Gro[i-1].rank;
		}
		else
		{

			Gro[i].rank = Gro[i-1].rank + 1;
		}
	}
	int a[4] = {0};
	for (int i = 0; i < 3; i++)
	{
		a[Gro[i].rank]++;
	}
	int count = 0;
	for (int i = 1; i < 4; i++)
	{
		int num = a[i];
		for (int j = 0; j < num; j++)
		{
			if (j == num - 1)
			{
				cout << '(' << Gro[j + count].i << ',' << Gro[j + count].score << ')' << endl;
			}
			else
			{
				cout << '(' << Gro[j+count].i << ',' << Gro[j+count].score << ")";
			}
		}
		count += num;
	}
	return 0;
}
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值