HD-ACM算法专攻系列(17)——find your present (2)

题目描述:

HD-ACM算法专攻系列(17)——find your present (2)_第1张图片

 

 HD-ACM算法专攻系列(17)——find your present (2)_第2张图片

 

源码:

 

#include"iostream"
#include"string"
using namespace std;

bool IsFirstHalf(string *strs, int n, string str)
{
	int count = 0;
	for(int i = 0; i < n; i++)
	{
		if(str < strs[i])count++;
	}
	return count >= (n / 2 + n % 2);
}

int main()
{
	int n, count[100], counts[5];
	string **strs;
	strs = new string*[5];
	for(int i = 0; i < 5; i++)
	{
		strs[i] = new string[100];
	}
	while(cin>>n)
	{
		if(n < 0)break;
		counts[1] = counts[2] = counts[3] = counts[4] = 0;
		for(int i = 0; i < n; i++)
		{
			cin>>count[i]>>strs[0][i];
			if(count[i] > 0 && count[i] < 5)
			{
				strs[count[i]][counts[count[i]]++] = strs[0][i];
			}
		}
		for(int i = 0; i < n; i++)
		{
			switch(count[i])
			{
				case 5:
					cout<<100< 
 

  

你可能感兴趣的:(HD-ACM算法专攻系列(17)——find your present (2))