题目描述:

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

 

 HD-ACM算法专攻系列(17)——find your present (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<<endl;
					break;
				case 0:
					cout<<50<<endl;
					break;
				default:
					if(IsFirstHalf(strs[count[i]], counts[count[i]], strs[0][i]))
					{
						cout<<55 + 10 * count[i]<<endl;
					}
					else
					{
						cout<<50 + 10 * count[i]<<endl;
					}
					break;
			}
		}
		cout<<endl;
	}
    return 0;
}

  

相关文章:

  • 2022-01-27
  • 2021-10-29
  • 2021-07-01
  • 2021-12-25
  • 2021-06-12
  • 2021-10-25
  • 2021-06-17
  • 2021-12-28
猜你喜欢
  • 2021-08-07
  • 2021-09-10
  • 2021-11-14
  • 2021-11-15
  • 2021-12-30
  • 2022-01-17
  • 2021-06-20
相关资源
相似解决方案