poj 1786 Bridge Hands

1 篇文章 0 订阅

Drivers of Advanced Cargo Movement, Ltd. usually have to wait quite a long time when waiting at border crossings for duty clearance. They are used to play various (card) games to have some fun. One of the games is Bridge. Playing Bridge involves dealing a standard deck of 52 cards to 4 players, so that each player receives 13 cards. Good players can then play with the hand as it is dealt, but most ordinary players will need to sort it, firstly by suit and then by rank within suit. There is no fixed ranking of the suits for this purpose, but it is useful to alternate the colors, so we will presume the following ordering: (club) < (diamond) < (spade) < (heart). (Note that because most character sets do not recognize these symbols, from now on we will use the more conventional C, D, S, and H). Within a suit, Ace is high, so the ordering is 
2 < 3 < 4 < 5 < 6 < 7 < 8 < 9 < T < J < Q < K < A . 
The players are usually called North, South, East, and West as they sit at the points of the compass. One player is designated the dealer and she deals one card to each player starting with the player on her left and proceeding clockwise until she deals the last card to herself. 

Write a program that will read in a representation of a deck of cards, deal them, sort them, and then display four sorted hands in the format shown below. 

Input

The input consists of a series of deals. Each deal begins with a line containing a single letter representing the dealer ("N", "E", "S", "W") followed by two lines representing the deck, card by card, as shown below. The first card given in the input is the first one to be dealt. The file is be terminated by a line consisting of a single hash character ("#").

Output

Output should consist of a series of sets of 24 lines, one set for each deal, separated by blank lines. Each set will consist of four groups of six lines displaying the sorted hands, in the order of their suit and rank. Use the format shown below. South player always goes first.

Sample Input

N
CQDTC4D8S7HTDAH7D2S3D6C6S6D9S4SAD7H2CKH5D3CTS8C9H3C3
DQS9SQDJH8HAS2SKD4H4S5C7SJC8DKC5C2CAHQCJSTH6HKH9D5HJ
#

Sample Output

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

#include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std;

struct puke
{
	char hs,dian;
	int num;
}play[4][20];

bool cmp(puke a,puke b)
{
    if(a.hs==b.hs)
    {
        return a.num<b.num;
    }
    else if(b.hs=='C')
    {
        if(a.hs=='D'||a.hs=='S'||a.hs=='H')
            return 0;
        return 1;
    }
    else if(b.hs=='D')
    {
        if(a.hs=='S'||a.hs=='H')
            return 0;
        return 1;
    }
    else if(b.hs=='S'&&a.hs=='H')
            return 0;
    return 1;
}

void print(int n)
{
    if(n==0) printf("South player:\n");
    else if(n==1) printf("West player:\n");
    else if(n==2) printf("North player:\n");
    else printf("East player:\n");

    printf("+---+---+---+---+---+---+---+---+---+---+---+---+---+\n");
    for(int i=0;i<12;i+=6)
        printf("|%c %c|%c %c|%c %c|%c %c|%c %c|%c %c",play[n][i].dian,play[n][i].dian,play[n][i+1].dian,play[n][i+1].dian,play[n][i+2].dian,play[n][i+2].dian,play[n][i+3].dian,play[n][i+3].dian,play[n][i+4].dian,play[n][i+4].dian,play[n][i+5].dian,play[n][i+5].dian);
    printf("|%c %c|\n",play[n][12].dian,play[n][12].dian);
    for(int i=0;i<12;i+=6)
        printf("| %c | %c | %c | %c | %c | %c ",play[n][i].hs,play[n][i+1].hs,play[n][i+2].hs,play[n][i+3].hs,play[n][i+4].hs,play[n][i+5].hs);
    printf("| %c |\n",play[n][12].hs);
   for(int i=0;i<12;i+=6)
        printf("|%c %c|%c %c|%c %c|%c %c|%c %c|%c %c",play[n][i].dian,play[n][i].dian,play[n][i+1].dian,play[n][i+1].dian,play[n][i+2].dian,play[n][i+2].dian,play[n][i+3].dian,play[n][i+3].dian,play[n][i+4].dian,play[n][i+4].dian,play[n][i+5].dian,play[n][i+5].dian);
    printf("|%c %c|\n",play[n][12].dian,play[n][12].dian);
    printf("+---+---+---+---+---+---+---+---+---+---+---+---+---+\n");
}
int main()
{
	char a,t[200],tt[100],k;
	int temp;scanf("%c",&a);getchar();
	while(a!='#')
	{
	    if(a=='S') temp=0;
	    else if(a=='W') temp=1;
	    else if(a=='N') temp=2;
	    else temp=3;
		k=0;
		for(int i=0;i<13;k++,i++)
        {
            for(int j=temp+1;j<temp+5;j++)
            {
                play[j%4][k].hs=getchar();
                if(play[j%4][k].hs=='\n')
                    play[j%4][k].hs=getchar();
                play[j%4][k].dian=getchar();

                if(play[j%4][k].dian>='2'&&play[j%4][k].dian<='9')
                    play[j%4][k].num=play[j%4][k].dian-'2';
                else if(play[j%4][k].dian=='T')play[j%4][k].num=10;
                else if(play[j%4][k].dian=='J')play[j%4][k].num=11;
                else if(play[j%4][k].dian=='Q')play[j%4][k].num=12;
                else if(play[j%4][k].dian=='K')play[j%4][k].num=13;
                else if(play[j%4][k].dian=='A')play[j%4][k].num=14;
            }
        }
        for(int i=0;i<4;i++)
        {
       //     print(i);
            sort(play[i],play[i]+13,cmp);
            print(i);
        }
        getchar();scanf("%c",&a);getchar();
        if(a!='#')
            printf("\n");
	}
	return 0;
}



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值