【C/C++】哈理工oj-我要当王者荣耀高手

Description:

王者荣耀是一款5v5团队竞技游戏,每一支队伍都需要五个人才可以进行游戏

游戏中总共有五个位置:对抗路,中路,发育路,打野,游走
(分别用字符串"duikanglu","zhonglu","fayulu","daye","youzou"对应),

给你n个人对应的位置信息以及能力值,你可以随意对其进行组队,你想要组建一支最强的战队(能力值总和越高则越强),

请你计算最高的能力值总和.若缺少对应位置则无法组建一支完整的队伍,输出-1

Input:

第一行一个整数T (1 <= T <= 1000),代表样例总数
每个样例第一行包含一个整数n (1 <= n <= 1000)

接下来n行每行为pi以及wi (1 <= wi <= 1000),

分别代表位置,能力值

Output:

输出一个整数,代表最强战队的能力值,或者一个整数-1,代表无法组建战队

Sample Input:

2
3
youzou 790
fayulu 985
duikanglu 756
5
daye 5
youzou 1
duikanglu 2
fayulu 3
zhonglu 4

Sample Output:

-1
15

#include<stdio.h>
#include<iostream>
#include<string>
int maxof(int n,int max)
{
	if (n >=max)
	{
		return n;
	}
	else
	{
		return max;
	}
}
using namespace std;
int main()
{
	int T, n;
	string str;
	int a = 0, b = 0, c = 0, d = 0, e = 0;
	int max1 = 0, max2 = 0, max3 = 0, max4 = 0, max5 = 0;
	int cap;
	int temp;
	int sum = 0;
	cin >> T;
	while (T--)
	{
		sum = 0;
		a = 0, b = 0, c = 0, d = 0, e = 0;
		max1 = 0, max2 = 0, max3 = 0, max4 = 0, max5 = 0;
		cin >> n;
		for (int i = 1; i <= n;i++)
		{			
			cin >> str;
			cin >> cap;
			if (str == "duikanglu")
			{				
				a++;
				max1 = maxof(cap, max1);
			}
			else if (str == "zhonglu")
			{
				b++;				
				max2 = maxof(cap, max2);
			}
			else if (str == "fayulu")
			{
				c++;				
				max3 = maxof(cap, max3);
			}
			else if (str == "daye")
			{
				d++;				
				max4= maxof(cap, max4);
			}
			else if (str == "youzou")
			{
				e++;				
				max5= maxof(cap, max5);
			}
		}
		if (a == 0 || b == 0 || c == 0 || d == 0 || e == 0)
		{
			cout << -1 << endl;
		}
		else
		{
			sum = max1 + max2 + max3 + max4 + max5;
			cout << sum<<endl;
		}
	}
	return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值