B东东学打牌----模拟题

题目

在这里插入图片描述

分析

这是一道模拟题,一步一步分析来走:
首先定义一个结构体people
{
name//人名
xu//一手牌的规则序号
key1,key2,key2//表示如果都是那一种一手牌,按关键字排序
}
有了上面的定义,我们只需要对每一个输入的人,分析他手中的一手牌是哪个规则序号(1:大牌 ;2:对子…),然后将这种牌的排序关键字记录到结构体里面(比如说是1大牌,关键字1就是5张牌的总和),这些用solve()函数解决。
解决完之后,就是多关键字排序的问题了。

代码:

#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string.h>
using namespace std;
struct people{
	char name[20];
	int xu,key1,key2,key3;
	bool operator <(const people &P){
		if(xu!=P.xu) return xu>P.xu;//升序
		else if(key1!=P.key1) return key1>P.key1;//升序
		else if(key2!=P.key2) return key2>P.key2;//升序
		else if(key3!=P.key3) return key3>P.key3;//升序
		else return strcmp(name, P.name)<=0;
	}
}thep[100005];
int wu[5];
void jiexi(char* S){
	int j=0,len=strlen(S);
	for(int i=0;i<len;i++){
		if(S[i]=='A') wu[j]=1;
		else if(S[i]=='1') wu[j]=10,i++;
		else if(S[i]=='J') wu[j]=11;
		else if(S[i]=='Q') wu[j]=12;
		else if(S[i]=='K') wu[j]=13;
		else wu[j]=S[i]-'0';
		j++;
	}
}
void solve(int i){
	sort(wu,wu+5);
	if(wu[0]==1&&wu[1]==10&&wu[2]==11&&wu[3]==12&&wu[4]==13){//龙顺
		thep[i].xu=8;
	}
	else if(wu[4]==wu[3]+1&&wu[3]==wu[2]+1&&wu[2]==wu[1]+1&&wu[1]==wu[0]+1){//顺子
		thep[i].xu=7;thep[i].key1=wu[4];
	}
	else if((wu[0]==wu[1]&&wu[1]==wu[2]&&wu[2]==wu[3])||(wu[1]==wu[2]&&wu[2]==wu[3]&&wu[3]==wu[4])){
		thep[i].xu=6;if(wu[0]!=wu[1]){
			thep[i].key1=wu[1];thep[i].key2=wu[0];
		}else{
			thep[i].key1=wu[1];thep[i].key2=wu[4];
		}
	}
	else if((wu[0]==wu[1]&&wu[2]==wu[3]&&wu[3]==wu[4])||wu[0]==wu[1]&&wu[1]==wu[2]&&wu[3]==wu[4]){
		thep[i].xu=5;if(wu[2]==wu[0]){
			thep[i].key1=wu[0];thep[i].key2=wu[4];
		}else{
			thep[i].key1=wu[4];thep[i].key2=wu[0];
		}
	}
	else if((wu[0]==wu[1]&&wu[0]==wu[2])||(wu[1]==wu[2]&&wu[2]==wu[3])||(wu[2]==wu[3]&&wu[3]==wu[4])){
		thep[i].xu=4;
		if(wu[0]==wu[1]){
			thep[i].key1=wu[0];thep[i].key2=wu[3]+wu[4];
		}else if(wu[3]==wu[4]){
			thep[i].key1=wu[4];thep[i].key2=wu[0]+wu[1];
		}else{
			thep[i].key1=wu[1];thep[i].key2=wu[0]+wu[4];
		}
	}
	else if((wu[0]==wu[1]&&wu[2]==wu[3])||(wu[0]==wu[1]&&wu[3]==wu[4])||(wu[1]==wu[2]&&wu[3]==wu[4])){
		thep[i].xu=3;if(wu[3]!=wu[4]){
			thep[i].key1=wu[2];thep[i].key2=wu[0];thep[i].key3=wu[4];
		}else if(wu[1]!=wu[2]){
			thep[i].key1=wu[3];thep[i].key2=wu[0];thep[i].key3=wu[2];
		}else{
			thep[i].key1=wu[3];thep[i].key2=wu[1];thep[i].key3=wu[0];
		}
	}
	else if(wu[0]==wu[1]||wu[1]==wu[2]||wu[2]==wu[3]||wu[3]==wu[4]){
		thep[i].xu=2;if(wu[0]==wu[1]){
			thep[i].key1=wu[0];thep[i].key2=wu[2]+wu[3]+wu[4];
		}else if(wu[1]==wu[2]){
			thep[i].key1=wu[1];thep[i].key2=wu[0]+wu[3]+wu[4];
		}else if(wu[2]==wu[3]){
			thep[i].key1=wu[2];thep[i].key2=wu[0]+wu[1]+wu[4];
		}else{
			thep[i].key1=wu[3];thep[i].key2=wu[0]+wu[1]+wu[2];
		}
	}
	else{
		thep[i].xu=1;thep[i].key1=wu[0]+wu[1]+wu[2]+wu[3]+wu[4];
	}
}
int main()
{
	int n;
	while(~scanf("%d",&n)){
		char puke[20];
		for(int i=0;i<n;i++){
			//初始化
			thep[i].key1=0;thep[i].key2=0;thep[i].key3=0;
			scanf("%s %s",&thep[i].name,&puke);
			jiexi(puke);
			solve(i);
		}
		sort(thep,thep+n);
		for(int i=0;i<n;i++){
			//cout<<thep[i].xu<<" "<<thep[i].key1<<" "<<thep[i].key2<<" "<<thep[i].key3<<" ";
			cout<<thep[i].name<<endl;
		}
	}
	return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值