POJ 1786Bridge Hands
来源:互联网 发布:淘宝助理5.5在哪下载 编辑:程序博客网 时间:2024/06/06 03:44
Description
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.
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
NCQDTC4D8S7HTDAH7D2S3D6C6S6D9S4SAD7H2CKH5D3CTS8C9H3C3DQS9SQDJH8HAS2SKD4H4S5C7SJC8DKC5C2CAHQCJSTH6HKH9D5HJ#
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<algorithm>#include<vector>#include<cstring>using namespace std;char s[1000];int start;struct abc{char x,y;abc();abc(char x,char y):x(x),y(y){};};int check(char c){if (c=='C') return 0;if (c=='D') return 1;if (c=='S') return 2;if (c=='H') return 3;}int get(char c){if (c=='A') return 14;if (c=='K') return 13;if (c=='Q') return 12;if (c=='J') return 11;if (c=='T') return 10;return c-'0';}bool cmp(const abc &a,const abc &b){if (a.x==b.x) return get(a.y)<get(b.y);return check(a.x)<check(b.x);}vector<abc> a[4];int main(){int f=0;while (~scanf("%s",s)){if (s[0]=='#') break;if (f) printf("\n"); else f=1;switch (s[0]){case'E':start=0; break;case'S':start=1; break;case'W':start=2; break;case'N':start=3; break;}for (int i=0;i<4;i++) a[i].clear();scanf("%s",s);scanf("%s",s+52);for (int i=0;i<104;i+=2,start=(start+1)%4)a[start].push_back(abc(s[i],s[i+1]));for (int i=0;i<4;i++) sort(a[i].begin(),a[i].end(),cmp);for (int i=0;i<4;i++){switch (i){case 0:printf("South player:\n"); break;case 1:printf("West player:\n"); break;case 2:printf("North player:\n"); break;case 3:printf("East player:\n"); break;}printf("+---+---+---+---+---+---+---+---+---+---+---+---+---+\n");for (int j=0;j<a[i].size();j++){printf("|%c %c",a[i][j].y,a[i][j].y);if (j==a[i].size()-1) printf("|\n");}for (int j=0;j<a[i].size();j++){printf("| %c ",a[i][j].x);if (j==a[i].size()-1) printf("|\n");}for (int j=0;j<a[i].size();j++){printf("|%c %c",a[i][j].y,a[i][j].y);if (j==a[i].size()-1) printf("|\n");}printf("+---+---+---+---+---+---+---+---+---+---+---+---+---+\n");}}return 0;}
1 0
- Poj 1786 Bridge Hands
- poj 1786 Bridge Hands
- POJ 1786Bridge Hands
- poj 1786 Bridge Hands
- POJ 1786 Bridge Hands 笔记
- ACM篇:POJ 1786--Bridge Hands
- UVa555 - Bridge Hands
- POJ 3283 Card Hands
- POJ-3283 Card Hands
- sdutoj 1101 Bridge Hands (桥牌)
- POJ 3283 Card Hands 可能会
- POJ 3283 Card Hands Trie树
- POJ-2573-Bridge
- POJ 2573 Bridge 贪心
- poj 2573 bridge
- Bridge Across Islands POJ
- poj 3608 Bridge Across Islands
- 【POJ 3608】Bridge Across Islands
- 有关ADB的问题
- C++的boost学习--内存管理
- 虚拟机类加载机制
- OGM 与mongodb
- ruby gem 下载官网无响应,需要到镜像
- POJ 1786Bridge Hands
- Oracle PL/SQL 培训
- 微信开发二三事:功能应用二、聊天机器人(2)
- 关键字final、static使用总结
- Linux系统结构与终端控制台
- 人生三阶段
- [BZOJ1911]APIO2010特别行动队|斜率优化DP
- 黑马程序员-JAVA-泛型粗解
- vi命令