POJ 2038 Team Rankings G++

本文介绍了如何运用G++编程解决POJ 2038团队排名挑战,通过实例解析算法思路,涉及排序、团队成绩计算等关键步骤。
摘要由CSDN通过智能技术生成

#include <iostream>
#include <string>
#include <algorithm>
#include <cstdio>
using namespace std;
//英语  抄博友程序   next_permutation     
string a[108];
int main()
{
	while(1)
	{
		int n;
		cin>>n;
		if(n==0)
		{
			break;
		}
		for(int i=0;i<n;i++)
		{
			cin>>a[i];
		}
		string s="ABCDE";
		string jg="ABCDE";
		int js=1000;
		do{
			int count=0;
			for(int i=0;i<n;i++)
			{
				for(int j=0;j<5;j++)
				{
					for(int k=j+1;k<5;k++)
					{
						char x=a[i][j];
						char y=a[i][k];
						int tj,tk;
						for(int h=0;h<5;h++)//抄博友 
						{
							if(s[h]==x)
							{
								tj=h;
							}
							if(s[h]==y)
							{
								tk=h;
							}
						}
						if(tj>tk)
						{
							count++;
						}
					}
				}
				//cout<<s<<" "<<a[i]<<" "<<count<<endl;
			}
			if(count<js)
			{
				js=count;
				jg=s;
				//cout<<jg<<" "<<js<<endl;
			}	
		}while(next_permutation(s.begin(),s.end()));
		cout<<jg<<" is the median ranking with value "<<js<<"."<<endl;
	}
	return 0;
}

 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值