C - Raytheon playing cards
Title Description
Ruishen HRZ is bored at home because of the epidemic. At the same time, he is very fierce. All his classes are water and water can get A +, so he is bored. He finds three other people: gugudong, TENGSHEN and zjm to play cards (the world's bitter Ruishen has been for A long time).
Obviously, the game is made up of four people in a circle. We call the four directions North, Southeast and West. The corresponding English is North, East, South, West. The game consists of 52 playing cards. At first, we appointed a dealer (one in the southeast and northwest, marked with English initials) to start licensing. The order of licensing was clockwise. The first dealer did not issue himself, but issued his next person (the next person clockwise). That way, everyone gets 13 cards.
Now we define the order of cards. First of all, the decor is (plum blossom) < (square piece) < (spade) < (red peach). (when inputting, we use C,D,S,H to represent plum blossom, square piece, spade, and red peach respectively, that is, the initial of the word). For deck values, we specify 2 < 3 < 4 < 5 < 6 < 7 < 8 < 9 < T < J < Q < K < a.
Now, as God, you have to sort everyone's cards from small to large and output them in a 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.
Next there are two lines, each with 52 characters, representing 26 cards, and the two lines add up to 52 cards. Each card consists of two characters. The first character represents the decor and the second character represents the value.
Output
Output multiple groups of data licensing results, each group of data after the need to output an additional blank line!!!!!
Each group of data should be composed of 24 lines. The output should be clockwise and always output south first As a result of player, each player first outputs one line, namely player name (southeast, northwest), then five lines, the first line and the fifth line output fixed format (see the example), the second line and the fourth line output values in order and format (see the example), and the third line output patterns in order and format (see the example).
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| +---+---+---+---+---+---+---+---+---+---+---+---+---+
Title Solution
- Each card is a structure card, including the design and size of the card, and the comparison function between the structures is overloaded according to the topic
- The design and size of the card in the structure are all represented by integers (0-3, 0-12). The conversion between integers and characters representing the design and face value of the card is realized by the char array flower and size. Integer storage facilitates the comparison of card sizes.
- Use a two-dimensional array of structures to represent everyone's cards. Input all card information through double loop, convert the input characters into integers and put them into card array, and reorder the card array of the player for each card. After entering the card array, the card array is in order.
- In order to determine the order among the four groups of cards in the output array, a conditional statement is used to selectively assign the information of the input and sorted card array to another array for output. A string array of 4 elements is defined to store the names of players representing four players in the southeast, northwest and northwest. Finally, the cycle output is enough.
Code
#include <iostream> using namespace std; /* run this program using the console pauser or add your own getch, system("pause") or input loop */ struct card{ int flo;//Flower color int siz;//Size bool operator==(card c){ return siz==c.siz&&flo==c.flo; } bool operator<(card c){ return (flo==c.flo)?siz<c.siz:flo<c.flo; } bool operator>(card c){ return (flo==c.flo)?siz>c.siz:flo>c.flo; } }; char flower[]={'C','D','S','H'};//0,1,2,3 char size[]={'2','3','4','5','6','7','8','9','T','J','Q','K','A'};//0,1,2,3,4........12 int main(int argc, char** argv) { char peo;//Dealer while(1){ cin>>peo; if(peo=='#'){break; } card car[4][13]; for(int ii=0;ii<13;ii++){ for(int jj=0;jj<4;jj++){ char flo,siz; int f,s; cin>>flo>>siz; for(int i=0;i<4;i++){ if(flo==flower[i]){f=i;} if(siz==size[i]){s=i;} } for(int i=4;i<13;i++){ if(siz==size[i]){s=i;} } car[jj][ii]={f,s};//Put cards in sequence for(int i=ii-1;i>=0;i--){//Sequence reorder if(car[jj][i]>car[jj][i+1]){ card tmp=car[jj][i]; car[jj][i]=car[jj][i+1]; car[jj][i+1]=tmp; } } } } card **pri=new card*[4]; if(peo=='N'){ pri[0]=car[1]; pri[1]=car[2]; pri[2]=car[3]; pri[3]=car[0]; } else if(peo=='W'){ pri[0]=car[2]; pri[1]=car[3]; pri[2]=car[0]; pri[3]=car[1]; } else if(peo=='E'){ pri[0]=car[0]; pri[1]=car[1]; pri[2]=car[2]; pri[3]=car[3]; } else if(peo=='S'){ pri[0]=car[3]; pri[1]=car[0]; pri[2]=car[1]; pri[3]=car[2]; } char *player[4]={"South player:","West player:","North player:","East player:"}; for(int ii=0;ii<4;ii++){ cout<<player[ii]<<endl; cout<<"+---+---+---+---+---+---+---+---+---+---+---+---+---+"<<endl; //First output number for(int i=0;i<13;i++){ cout<<"|"<<size[pri[ii][i].siz]<<" "<<size[pri[ii][i].siz]; } cout<<"|"<<endl; // Output color for(int i=0;i<13;i++){ cout<<"|"<<" "<<flower[pri[ii][i].flo]<<" "; } cout<<"|"<<endl; //Second output digit for(int i=0;i<13;i++){ cout<<"|"<<size[pri[ii][i].siz]<<" "<<size[pri[ii][i].siz]; } cout<<"|"<<endl; cout<<"+---+---+---+---+---+---+---+---+---+---+---+---+---+"<<endl; } cout<<endl; } return 0; }