subject
Raytheon HRZ was bored because he was idle at home and at the same time he was terrific. All his classes were water and he could get A+. So he was bored and got three other people: Googu Dong, Teng Shen and zjm to play cards (the world has been bitter and Rui Shen for a long time).
Obviously, the board is made up of four people, in a circle.We call the four directions north, south, East and west.The corresponding English is North, East, South, West.The game consists of a set of 52 cards.To begin, we assign a dealer (one in the southeast and northwest, identified by the English initials) to start the deal in a clockwise order, where the first dealer does not issue himself but his next person (the next one clockwise).That way, everyone gets 13 cards.
Now we define the order of cards. First, the pattern is (club)< (diamond)< (spade)< (hearts). (When entering, we use C, D, S, H for club, diamond, spade, hearts, that is, the first letter of the word.)For face values, we specify 2 < 3 < 4 < 5 < 6 < 7 < 8 < 9 < T < J < Q < K < A.
Now that you are God, you have to sort each person's cards from smallest to largest and output them in the given format.(See output description and sample output for specific format).
Input
Input contains multiple sets of data
The first line of each set of data contains an uppercase character indicating who the dealer is.If the character is'#', it means the end of input.
There are two next lines, each with 52 characters, representing 26 cards. Together, the two lines add up to 52 cards.Each card consists of two characters, the first representing the suit and the second representing the value.
Output
Output multiple sets of data licensing results, each set of data after the need to output an additional blank line (that is, multiple sets of data between blank lines, there is also a blank line at the end of the text).
Each set of data should consist of 24 rows with the output clockwise, always South firstPlayer's result is that each player outputs one line, the name of the player (southeast, northwest), the next five lines, the first and fifth lines outputting a fixed format (see sample), the second and fourth lines outputting values in order and format (see sample), and the third line outputting colors in order and format (see sample).
Sample Input
N
CTCAH8CJD4C6D9SQC7S5HAD2HJH9CKD3H6D6D7H3HQH4C5DKHKS9
SJDTS3S7S4C4CQHTSAH2D8DJSTSKS2H5D5DQDAH7C9S8C8S6C2C3
#
Sample 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 |
±- - ±- - ±- - ±- - ±- - ±- - ±- - ±- - ±- - ±- - ±- - ±- - ±- - +
thinking
This question can be sorted by multiple keywords.
Primary key (suit): C < D < S < H
Subkeywords (face value): 2 < 3 < 4 < 5 < 6 < 7 < 8 < 9 < T < J < Q < K < A
Using the sort function in STL, write an appropriate comparison function:
1. When the colors are different, only the comparative values of the colors are returned.
(2) Return the comparative value of the face value when the colors are the same.
Code
#include <iostream> #include <vector> #include <map> #include <queue> #include <utility> #include <algorithm> #include <stdlib.h> #include <string.h> using namespace std; // Pair<char, char> p; the first is the suit, the second number int iconValue(const char c) { switch (c) { case 'C': return 0; case 'D': return 1; case 'S': return 2; default: // 'H' return 3; } } int numValue(const char c) { if (c >= '2' && c <= '9') return c - '0'; switch (c) { case 'T': return 10; case 'J': return 11; case 'Q': return 12; case 'K': return 13; default: // 'A' return 14; } } // Compare colors before numbers bool cmp(const pair<char, char>& p1, const pair<char, char>& p2) { if (p1.first != p2.first) return iconValue(p1.first) < iconValue(p2.first); else return numValue(p1.second) < numValue(p2.second); } void printCards(vector<pair<char, char>> v) { cout << "+---+---+---+---+---+---+---+---+---+---+---+---+---+" << endl; cout << "|"; for (vector<pair<char, char>>::iterator it = v.begin(); it != v.end(); it++) { cout << (*it).second << " " << (*it).second << "|"; } cout << endl; cout << "|"; for (vector<pair<char, char>>::iterator it = v.begin(); it != v.end(); it++) { cout << " " << (*it).first << " " << "|"; } cout << endl; cout << "|"; for (vector<pair<char, char>>::iterator it = v.begin(); it != v.end(); it++) { cout << (*it).second << " " << (*it).second << "|"; } cout << endl; cout << "+---+---+---+---+---+---+---+---+---+---+---+---+---+" << endl; } void print(vector<int> v) { vector<int>::iterator i1 = v.begin(); vector<int>::iterator i2 = v.begin(); i2++; while (i2 != v.end()) { cout << *i1 << " "; i1++; i2++; } cout << *i1 << endl; } int main() { char pos; cin >> pos; while (pos != '#') { string order; if (pos == 'N') order = "4123"; else if (pos == 'E') order = "1234"; else if (pos == 'S') order = "2341"; else order = "3412"; string print_order[] = { "South player:","West player:","North player:" ,"East player:" }; vector<pair<char, char>> v[4]; for (int i = 0; i < 13; i++) { for (int j = 0; j < 4; j++) { char icon, num; cin >> icon >> num; pair<char, char> p(icon, num); v[j].push_back(p); } } for (int i = 0; i < 4; i++) { sort(v[i].begin(), v[i].end(), cmp); } cout << "South player:" << endl; int index = order.find(1 + '0'); printCards(v[index]); cout << "West player:" << endl; index = order.find(2 + '0'); printCards(v[index]); cout << "North player:" << endl; index = order.find(3 + '0'); printCards(v[index]); cout << "East player:" << endl; index = order.find(4 + '0'); printCards(v[index]); cout << endl; cin >> pos; } }
End