打扑克

题目:
瑞神HRZ因为疫情在家闲得无聊,同时他又非常厉害,所有的课对他来说都是水一水就能拿A+,所以他无聊,找来了另外三个人:咕咕东,腾神以及zjm来打牌(天下苦瑞神久矣)。
显然,牌局由四个人构成,围成一圈。我们称四个方向为北 东 南 西。对应的英文是North,East,South,West。游戏一共由一副扑克,也就是52张构成。开始,我们指定一位发牌员(东南西北中的一个,用英文首字母标识)开始发牌,发牌顺序为顺时针,发牌员第一个不发自己,而是发他的下一个人(顺时针的下一个人)。这样,每个人都会拿到13张牌。
现在我们定义牌的顺序,首先,花色是(梅花)<(方片)<(黑桃)<(红桃),(输入时,我们用C,D,S,H分别表示梅花,方片,黑桃,红桃,即其单词首字母)。对于牌面的值,我们规定2 < 3 < 4 < 5 < 6 < 7 < 8 < 9 < T < J < Q < K < A。
现在你作为上帝,你要从小到大排序每个人手中的牌,并按照给定格式输出。(具体格式见输出描述和样例输出)。

input:
输入包含多组数据
每组数据的第一行包含一个大写字符,表示发牌员是谁。如果该字符为‘#’则表示输入结束。
接下来有两行,每行有52个字符,表示了26张牌,两行加起来一共52张牌。每张牌都由两个字符组成,第一个字符表示花色,第二个字符表示数值。

output:
输出多组数据发牌的结果,每组数据之后需要额外多输出一个空行!!!!!
每组数据应该由24行的组成,输出按照顺时针方向,始终先输出South Player的结果,每位玩家先输出一行即玩家名称(东南西北),接下来五行,第一行和第五行输出固定格式(见样例),第二行和第四行按顺序和格式输出数值(见样例),第三行按顺序和格式输出花色(见样例)。

Example:

input:

N
CTCAH8CJD4C6D9SQC7S5HAD2HJH9CKD3H6D6D7H3HQH4C5DKHKS9
SJDTS3S7S4C4CQHTSAH2D8DJSTSKS2H5D5DQDAH7C9S8C8S6C2C3
#

output:

South player:
+---+---+---+---+---+---+---+---+---+---+---+---+---+
|6 6|A A|6 6|J J|5 5|6 6|7 7|9 9|4 4|5 5|7 7|9 9|T T|
| C | C | D | D | S | S | S | S | H | H | H | H | H |
|6 6|A A|6 6|J J|5 5|6 6|7 7|9 9|4 4|5 5|7 7|9 9|T T|
+---+---+---+---+---+---+---+---+---+---+---+---+---+
West player:
+---+---+---+---+---+---+---+---+---+---+---+---+---+
|2 2|5 5|9 9|K K|5 5|7 7|9 9|4 4|T T|J J|A A|8 8|A A|
| C | C | C | C | D | D | D | S | S | S | S | H | H |
|2 2|5 5|9 9|K K|5 5|7 7|9 9|4 4|T T|J J|A A|8 8|A A|
+---+---+---+---+---+---+---+---+---+---+---+---+---+
North player:
+---+---+---+---+---+---+---+---+---+---+---+---+---+
|3 3|4 4|J J|2 2|3 3|T T|Q Q|K K|8 8|Q Q|K K|2 2|3 3|
| C | C | C | D | D | D | D | D | S | S | S | H | H |
|3 3|4 4|J J|2 2|3 3|T T|Q Q|K K|8 8|Q Q|K K|2 2|3 3|
+---+---+---+---+---+---+---+---+---+---+---+---+---+
East player:
+---+---+---+---+---+---+---+---+---+---+---+---+---+
|7 7|8 8|T T|Q Q|4 4|8 8|A A|2 2|3 3|6 6|J J|Q Q|K K|
| C | C | C | C | D | D | D | S | S | H | H | H | H |
|7 7|8 8|T T|Q Q|4 4|8 8|A A|2 2|3 3|6 6|J J|Q Q|K K|
+---+---+---+---+---+---+---+---+---+---+---+---+---+

思路:
这题主要考察排序问题,且要根据题意进行排序,可利用一个函数将每个字符代表相应的数字,进而直接判断,最后比较复杂的输出。

代码:

#include<iostream>
#include<string.h>
#include<algorithm>
using namespace std;
struct node
{
	char first;
	char second;
};
node n1[20],n2[20],n3[20],n4[20];
int t(const char p)
{
	switch(p){
		case 'C':return 1;
		case 'D':return 2;
		case 'S':return 3;
		case 'H':return 4;
		case '2':return 5;
		case '3':return 6;
		case '4':return 7;
		case '5':return 8;
		case '6':return 9;
		case '7':return 10;
		case '8':return 11;
		case '9':return 12;
		case 'T':return 13;
		case 'J':return 14;
		case 'Q':return 15;
		case 'K':return 16;
		case 'A':return 17;
	}
	
}
int comparee(node p,node q)
{
	return (t(p.first)<t(q.first)||(t(p.first)==t(q.first)&&t(p.second)<t(q.second)));
}
void printfn1()
{
	cout << "+---+---+---+---+---+---+---+---+---+---+---+---+---+" << endl;
		cout << "|";
	for(int i=0;i<13;i++)
			{
			cout << n1[i].second << " " <<n1[i].second << "|";
			}
			cout << endl;
			cout << "|";
			for(int i=0;i<13;i++)
			{
				cout <<" " << n1[i].first << " |";
			}
			cout << endl;
			cout << "|";
			for(int i=0;i<13;i++)
			{
			cout << n1[i].second << " " <<n1[i].second << "|";
			}
			cout << endl;
			cout << "+---+---+---+---+---+---+---+---+---+---+---+---+---+" << endl;
}
void printfn2()
{
	cout << "+---+---+---+---+---+---+---+---+---+---+---+---+---+" << endl;
		cout << "|";
	for(int i=0;i<13;i++)
			{
			cout << n2[i].second << " " <<n2[i].second << "|";
			}
			cout << endl;
			cout << "|";
			for(int i=0;i<13;i++)
			{
				cout <<" " << n2[i].first << " |";
			}
			cout << endl;
			cout << "|";
			for(int i=0;i<13;i++)
			{
			cout << n2[i].second << " " <<n2[i].second << "|";
			}
			cout << endl;
			cout << "+---+---+---+---+---+---+---+---+---+---+---+---+---+" << endl;
}
void printfn3()
{
	cout << "+---+---+---+---+---+---+---+---+---+---+---+---+---+" << endl;
		cout << "|";
	for(int i=0;i<13;i++)
			{
			cout << n3[i].second << " " <<n3[i].second << "|";
			}
			cout << endl;
			cout << "|";
			for(int i=0;i<13;i++)
			{
				cout <<" " << n3[i].first << " |";
			}
			cout << endl;
			cout << "|";
			for(int i=0;i<13;i++)
			{
			cout << n3[i].second << " " <<n3[i].second << "|";
			}
			cout << endl;
			cout << "+---+---+---+---+---+---+---+---+---+---+---+---+---+" << endl;
}
void printfn4()
{
	cout << "+---+---+---+---+---+---+---+---+---+---+---+---+---+" << endl;
		cout << "|";
	for(int i=0;i<13;i++)
			{
			cout << n4[i].second << " " <<n4[i].second << "|";
			}
			cout << endl;
			cout << "|";
			for(int i=0;i<13;i++)
			{
				cout <<" " << n4[i].first << " |";
			}
			cout << endl;
			cout << "|";
			for(int i=0;i<13;i++)
			{
			cout << n4[i].second << " " <<n4[i].second << "|";
			}
			cout << endl;
			cout << "+---+---+---+---+---+---+---+---+---+---+---+---+---+" << endl;
}
int main()
{
	char x;
	while(1)
	{
		cin >> x;
		if(x=='#')
		break;
		int m1=0,m2=0,m3=0,m4=0;
		char a[52];
		char b[52];
		scanf("%s",&a);
		scanf("%s",&b);
		for(int i=0;i<=40;i=i+8)
		{
			n1[m1].first=a[i];n1[m1++].second=a[i+1];
			n1[m1].first=b[i+4];n1[m1++].second=b[i+5];
			n2[m2].first=a[i+2];n2[m2++].second=a[i+3];
			n2[m2].first=b[i+6];n2[m2++].second=b[i+7];
			n3[m3].first=a[i+4];n3[m3++].second=a[i+5];
			n3[m3].first=b[i];n3[m3++].second=b[i+1];
			n4[m4].first=a[i+6];n4[m4++].second=a[i+7];
			n4[m4].first=b[i+2];n4[m4++].second=b[i+3];
		}
		n1[m1].first=a[48];n1[m1++].second=a[49];
		n2[m2].first=a[50];n2[m2++].second=a[51];
		n3[m3].first=b[48];n3[m3++].second=b[49];
		n4[m4].first=b[50];n4[m4++].second=b[51];//给每位玩家相应的牌。 
		sort(n1,n1+13,comparee);
		sort(n2,n2+13,comparee);
		sort(n3,n3+13,comparee);
		sort(n4,n4+13,comparee);//利用已有规则进行排序 
		if(x=='E')
		{
		cout << "South player:" << endl;
		printfn1();
		cout << "West player:" << endl;
		printfn2();
		cout << "North player:" << endl;
		printfn3();
		cout << "East player:" << endl;
		printfn4();
		}
		if(x=='S')
		{
		cout << "South player:" << endl;
		printfn4();
		cout << "West player:" << endl;
		printfn1();
		cout << "North player:" << endl;
		printfn2();
		cout << "East player:" << endl;
		printfn3();
		}
		if(x=='W')
		{
		cout << "South player:" << endl;
		printfn3();
		cout << "West player:" << endl;
		printfn4();
		cout << "North player:" << endl;
		printfn1();
		cout << "East player:" << endl;
		printfn2();
		}
		if(x=='N')
		{
		cout << "South player:" << endl;
		printfn2();
		cout << "West player:" << endl;
		printfn3();
		cout << "North player:" << endl;
		printfn4();
		cout << "East player:" << endl;
		printfn1();
		}	
		cout << endl;
	}
 } 

结果:
在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值