week2 experiment C

Meaning of the questions:
Rui God HRZ since the epidemic at home bored, and he has a very powerful, all classes are for him to be able to get water, a water A +, so he was bored, and got three other people: Cuckoo East Teng God and zjm to play cards (Swiss world suffering God for some time now).
Clearly, the Board consists of four individuals, circle. We call for the North East West four directions. Corresponding English is the North, East, South, West. Game total, which is 52 consists of a poker. The beginning, we appoint a dealer (in a truck, with the English initials logo) began licensing, licensing clockwise order, the dealer does not send their own first, but made his next people (clockwise next person). In this way, everyone will get 13 cards.
Now we define the order of the cards, first color is (plum) <(square sheet) <(spades) <(hearts), (input, we use C, D, S, H, respectively plum, square piece, spades, hearts, namely that the first letter of the word). For values of the sign face, we require 2 <3 <4 <5 < 6 <7 <8 <9 <T <J <Q <K <A.
Now you, as God, you have to sort everyone from small to large hands of cards, and set the output format to follow. (See particular output format description and sample output).
Input:
input contains multiple sets of data
of the first line of each data contains an uppercase character, who represents the dealer yes. If the character is a '#' indicates the end of input.
The next two lines, 52 characters per line, shows 26 cards, two lines add up to a total of 52 cards. Each card consists of two characters, the first character represents the color, the second character indicates values.
Output:
Output multiple sets of result data licensing, additional multi-output data after each set of a blank line! ! ! ! !
Each set of data to be composed, the output line 24 in the clockwise direction, always to the output of South Player, i.e. each player to player name output line (truck), followed by five elements, the first and fifth lines output fixation format (see examples), the second and fourth rows in the order and format of the output values (see examples), the third row and the format of the output color sequence (see examples).
INPUT the Sample:
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 | JJ | 2 2 |. 3. 3 | TT | QQ | KK |. 8. 8 | QQ | KK | 2 2 |. 3. 3 |
± - ± - ± - ± - ± - ± - ± - ± - ± - ± - ± - ± - ± - +
East Player:
± - ± - ± - ± - ± - ± - ± - ± - ± - ± - ± - ± - ± - +
|. 7. 7 |. 8. 8 | TT | QQ |. 4. 4 |. 8. 8 | AA | 2 2 |. 3. 3 |. 6. 6 | JJ | QQ | KK |
| C | C | C | C | D | D | D | S | S | H | H | H | H |
|. 7. 7 |. 8. 8 | TT | QQ |. 4. 4 |. 8. 8 | AA | 2 2 |. 3. 3 |. 6. 6 | JJ | QQ | KK |
± - ± - ± - ± - ± - ± - ± - ± - ± - ± - ± - ± - ± - +
ideas:
first, define a structure comprises a digital card size and color, color and digital conversion, to convert the char to an int. Direction defining the beginning of the input, if the input is the #, then exit. When the card during sequential distribution by cyclic achieved, since the input is an input into two rows, half cycle when the input to be continued after the input card number and suit through a branch processing getchar (). Then interpretation of the direction input, direction because there are four directions, when the direction is not the same, the results are not the same brand distribution. When the result of the output, are output beginning south direction, and outputs in the form of output format, since the size of the first digital output, then the next line of output color, output the next line in the size of the figures. Therefore, by determining the cycle, by determining whether the i, i 0,1,2 can take three numbers, i.e. the second row when the output color i is 1, i is 0 and 2, namely the first and third row digital output.
代码:
#include
#include
#include
#include
#include
#include
using namespace std;
map<char,int> num;
map<char,int> flower;
struct node{
char number;
char flow;
bool operator<(const node& te) const
{
if(flow!=te.flow)
//return flow<te.flow;
return flower[flow]<flower[te.flow];
//return number<te.number;
return num[number]<num[te.number];
}
}temp[4][13];
int main()
{
//char num[]={‘2’,‘3’,‘4’,‘5’,‘6’,‘7’,‘8’,‘9’,‘T’,‘J’,‘Q’,‘K’,‘A’};
//flower[10]={‘C’,‘D’,‘S’,‘H’};
num[‘2’]=0;
num[‘3’]=1;
num[‘4’]=2;
num[‘5’]=3;
num[‘6’]=4;
num[‘7’]=5;
num[‘8’]=6;
num[‘9’]=7;
num[‘T’]=8;
num[‘J’]=9;
num[‘Q’]=10;
num[‘K’]=11;
num[‘A’]=12;
flower[‘C’]=0;
flower[‘D’]=1;
flower[‘S’]=2;
flower[‘H’]=3;
char begin;
while(1)
{
scanf("%c",&begin);
if(begin==’#’)
return 0;
getchar();
for(int i=0,j=0;j!=13;j++,i=0)
{
scanf("%c",&temp[i][j].flow);
scanf("%c",&temp[i][j].number);
i++;
scanf("%c",&temp[i][j].flow);
scanf("%c",&temp[i][j].number);
if(j6)
getchar();
i++;
scanf("%c",&temp[i][j].flow);
scanf("%c",&temp[i][j].number);
i++;
scanf("%c",&temp[i][j].flow);
scanf("%c",&temp[i][j].number);
}
getchar();
for(int i=0;i<4;i++)
{
sort(temp[i],temp[i]+13);
}
int am[4];
if(begin
’N’)
{
am[0]=1;
am[1]=2;
am[2]=3;
am[3]=0;
}
else if(begin==‘E’)
{
am[0]=0;
am[1]=1;
am[2]=2;
am[3]=3;
}
else if(begin==‘S’)
{
am[0]=3;
am[1]=0;
am[2]=1;
am[3]=2;
}
else if(begin==‘W’)
{
am[0]=2;
am[1]=3;
am[2]=0;
am[3]=1;
}
int cm;
cout<<“South player:”<<endl;
cout<<“±–±--±–±--±–±--±–±--±–±--±–±--±–+”<<endl;
cm=am[0];
for(int i=0;i<3;i++)
{
for(int j=0;j<13;j++)
{
if(i!=1)
{
cout<<"|"<<temp[cm][j].number<<" “<<temp[cm][j].number;
}
else
{
cout<<”|"<<" “<<temp[cm][j].flow<<” ";
}

	}
	cout<<"|"<<endl;
}
cout<<"+---+---+---+---+---+---+---+---+---+---+---+---+---+"<<endl;
cout<<"West player:"<<endl;
cout<<"+---+---+---+---+---+---+---+---+---+---+---+---+---+"<<endl;
cm=am[1];
for(int i=0;i<3;i++)
{
	for(int j=0;j<13;j++)
	{
		if(i!=1)
		{
			cout<<"|"<<temp[cm][j].number<<" "<<temp[cm][j].number;
		}
		else
		{
			cout<<"|"<<" "<<temp[cm][j].flow<<" ";
		}
		
	}
	cout<<"|"<<endl;
}
cout<<"+---+---+---+---+---+---+---+---+---+---+---+---+---+"<<endl;
cout<<"North player:"<<endl;
cout<<"+---+---+---+---+---+---+---+---+---+---+---+---+---+"<<endl;
cm=am[2];
for(int i=0;i<3;i++)
{
	for(int j=0;j<13;j++)
	{
		if(i!=1)
		{
			cout<<"|"<<temp[cm][j].number<<" "<<temp[cm][j].number;
		}
		else
		{
			cout<<"|"<<" "<<temp[cm][j].flow<<" ";
		}
		
	}
	cout<<"|"<<endl;
}
cout<<"+---+---+---+---+---+---+---+---+---+---+---+---+---+"<<endl;
cout<<"East player:"<<endl;
cout<<"+---+---+---+---+---+---+---+---+---+---+---+---+---+"<<endl;
cm=am[3];
for(int i=0;i<3;i++)
{
	for(int j=0;j<13;j++)
	{
		if(i!=1)
		{
			cout<<"|"<<temp[cm][j].number<<" "<<temp[cm][j].number;
		}
		else
		{
			cout<<"|"<<" "<<temp[cm][j].flow<<" ";
		}
		
	}
	cout<<"|"<<endl;
}
cout<<"+---+---+---+---+---+---+---+---+---+---+---+---+---+"<<endl;
	cout<<endl;
}
return 0;

}

Published 19 original articles · won praise 0 · Views 218

Guess you like

Origin blog.csdn.net/weixin_45117273/article/details/104738691