# Assignment part

## A - Maze

There is a map in Dongdong. I want to find Meizhi through the map. The map shows that 0 means you can walk, 1 means you can't walk, the upper left corner is the entrance, and the lower right corner is Meizhi. These two positions are guaranteed to be 0. Now that you know the map, it's not difficult for Dongdong to find Meizhi. Please make a program to write the shortest route for Dongdong to find Meizhi.
Input
The input is a 5 × 5 two-dimensional array, which only consists of 0 and 1 numbers, representing the normal map.
Output
Output several lines to represent the coordinates of the shortest path from the upper left corner to the lower right corner in turn, with the format shown in the example. Data guarantees a unique solution.
Sample Input
0 1 0 0 0
0 1 0 1 0
0 1 0 1 0
0 0 0 1 0
0 1 0 1 0
Sample Output
(0, 0)
(1, 0)
(2, 0)
(3, 0)
(3, 1)
(3, 2)
(2, 2)
(1, 2)
(0, 2)
(0, 3)
(0, 4)
(1, 4)
(2, 4)
(3, 4)
(4, 4)
Hint
The coordinate (x, y) indicates the row X and column y, the number of which starts from 0 and takes the upper left corner as the origin.
Also note that there should be a space after the comma separating the coordinates in the output.

### Analysis:

This is a classic maze problem. Look for the path from the top left corner to the bottom right corner. The overall idea is to find the path through BFS. The BFS method is to use a queue, which is realized by two offset arrays. The path is saved by a two-dimensional array path of the originally declared point class. Path[x][y] (point type) stores the coordinates of its previous point, so that its path can be found in turn. When outputting, starting from the end point (4, 4), push the arriving point into the stack, and then push the path [] [] (i.e. its previous point) corresponding to this point into the stack. Loop this process until (0, 0), and then the complete path can be inverted into the stack. Just output.

### Source code:

```#include<iostream>
#include<queue>
#include<stack>
using namespace std;
// basic operation
struct point
{
int x;
int y;
point(int x, int y) : x(x), y(y){}
point(){}
}path;

bool vis;
int a, dis;
int sx, sy, tx, ty;
queue<point> Q;
stack<point> s;
int dy[] = {-1, 1, 0, 0};
int dx[] = {0, 0, -1, 1};

// BFS, implemented by queue and offset array
int bfs()
{
Q.push(point(sx, sy));
vis[sx][sy] = true;
dis[sx][sy] = 0;
while(!Q.empty())
{
point now = Q.front();
Q.pop();
// Up, down, left and right looking for accessible points
for(int i = 0 ; i < 4 ; ++i)
{
int x = now.x + dx[i], y = now.y + dy[i];
if(x >= 0 && x < 5 && y >= 0 && y < 5 && vis[x][y] == 0 && a[x][y] == 0)
{
dis[x][y] = dis[now.x][now.y] + 1;
vis[x][y] = 1;
Q.push(point(x, y));
// Record the coordinates of the previous point with path [] []
path[x][y] = point(now.x, now.y);
}
}
}
return 0;
}
int main()
{
for(int i = 0 ; i < 5 ; i++)
for(int j = 0 ; j < 5 ; j++)
vis[i][j] = 0;
for(int i = 0 ; i < 5 ; i++)
for(int j = 0 ; j < 5 ; j++)
cin >> a[i][j];
bfs();

// Stack, find path
int px = 4, py = 4;
while(true)
{
s.push(point(px, py));

int b = px, c = py;
px = path[b][c].x;
py = path[b][c].y;
if(px == 0 && py == 0)
break;
}

// Output path
cout << "(0, 0)" << endl;
point step;
while(!s.empty())
{
step = s.top();
s.pop();
cout << "(" << step.x << ", " << step.y << ")" << endl;
}
return 0;
}

```

## B - Pour Water

Water pouring problem "fill A" means to fill cup A, "empty A" means to empty cup A, "pour A B" means to pour water of A into cup B and fill cup B or empty cup A.
Input
The input contains multiple sets of data. Each group of data input A, B, C data range 0 < A < = B, C < = B < = 1000, A and B mutual quality.
Output
The output of your program will consist of a series of instructions. These outputs will cause any tank to contain exactly C units of water. The last line of output for each set of data should be "success.". The output line starts at column 1 and should not have blank lines or any trailing spaces.
Sample Input
2 7 5
2 7 4
Sample Output
fill B
pour B A
success
fill A
pour A B
fill A
pour A B
success
Notes
If your output is different from Sample Output, it doesn't matter. The answer to a certain "A B C" question is multi-resolution. You can't judge whether your program is correct or not by standard text comparison. Therefore, SPJ (Special Judge) program is used to determine whether the code you write is correct.

### Analysis:

This is an implicit graph problem. Similar to the maze problem, taking the final water quantity 4 as an example, this problem is equivalent to the maze from the initial state of (0, 0) to the end point (4, n) or (m, 4). So we use BFS to achieve this. To facilitate output, we add a string variable string s to the structure status to store sentences such as "fill A", "pour A B".

### Source code:

```#include<queue>
#include<iostream>
#include<string>
#define maxn 1000
using namespace std;

int vis[maxn][maxn];

// Nodes of implicit graph
struct status
{
int a;  // A cup water volume
int b;  // B cup water volume
int step;  // Step number
string s[maxn];  // Operation name
}form;

// BFS
int bfs(int A, int B, int C)
{
status node;
// Initialization (0, 0), which is also the initial state
node.a = 0;
node.b = 0;
node.step = 0;

queue<status> q;
q.push(node);

while(!q.empty())
{
status t = q.front();
q.pop();

// End flag
if(t.a == C || t.b == C)
{
form = t;
return 1;
}
// vis[A][t.b] means that cup b is stationary and cup a is full
// When vis[A][t.b] is 0, it means that this point has not been reached. Perform the following operations
if(!vis[A][t.b])
{
status p;
p = t;
p.a = A;   // Fill A up
vis[p.a][p.b] = 1; // Tag arrived
p.step++;  // Step plus one
p.s[p.step] = "fill A"; // Record operation name
q.push(p); // Join the team
}

//The following situations are similar, no more detailed comments

// vis[t.a][B] means that cup a is stationary and cup B is full
if(!vis[t.a][B])
{
status p;
p = t;
p.b = B;
vis[p.a][p.b] = 1;
p.step++;
p.s[p.step] = "fill B";
q.push(p);
}
// vis[t.b] means that cup b is stationary and cup a is empty
if(!vis[t.b])
{
status p;
p = t;
p.a = 0;
vis[p.a][p.b] = 1;
p.step++;
p.s[p.step] = "empty A";
q.push(p);
}
// vis[t.a][B] means that cup a is stationary and cup B is empty
if(!vis[t.a])
{
status p;
p = t;
p.b = 0;
vis[p.a][p.b] = 1;
p.step++;
p.s[p.step] = "empty B";
q.push(p);
}
// A. pour all the water into B. if the remaining water in a is not enough to make B full, a becomes 0 and B becomes a + b
// If B is full and overflows, B is full, A is a + b - B
if(!vis[(B - t.b >= t.a) ? 0 : t.a - B + t.b][(B - t.b >= t.a) ? t.a + t.b : B])
{
status p;
p = t;
p.a = (B - t.b >= t.a) ? 0 : t.a - B + t.b;
p.b = (B - t.b >= t.a) ? t.a + t.b : B;
vis[p.a][p.b] = 1;
p.step++;
p.s[p.step] = "pour A B";
q.push(p);
}
// B. pour all the water into A. if the remaining water in B is not enough to make A full, B becomes 0 and A becomes a + b
// If it can make a full and overflow, then a full, B is a + b - A
if(!vis[(A - t.a >= t.b) ? t.a + t.b : A][(A - t.a >= t.b) ? 0 : t.b - A + t.a])
{
status p;
p = t;
p.a = (A - t.a >= t.b) ? t.a + t.b : A;
p.b = (A - t.a >= t.b) ? 0 : t.b - A + t.a;
vis[p.a][p.b] = 1;
p.step++;
p.s[p.step] = "pour B A";
q.push(p);
}
}
return 0;2
}

int main()
{
int A, B, C;

while(cin >> A >> B >> C)
{
int m = max(A, B);
for(int i = 0 ; i < m ; i++)
for(int j = 0 ; j < m ; j++)
vis[i][j] = 0;
bfs(A, B, C);
// Output s [] is the operation name. Note that this solution is not unique.
for(int i = 1 ; i <= form.step ; i++)
cout << form.s[i] << endl;
cout << "success" << endl;
}
}
```

### Review:

When testing this problem on VJ, CE error just happened. After analysis, it is found that there is no reference to the header file in the code, which makes cout unable to output the string type directly. After careful understanding, we found that different compilers have different output to cout. C + + compilers can't cout string type without it, while G + + can.

# Experimental part

## A - Chemistry (GNU G + + for compiler)

Chemistry is amazing. Here are alkanes. Suppose, as shown in the figure above, this alkane group has 6 atoms and 5 chemical bonds, 6 atoms are labeled 1-6 respectively, and then a pair of numbers a and b indicate that there is a chemical bond between atom A and atom b. In this way, five lines a and b can describe an alkane group
There is no numbering method for atoms, such as
1 2
2 3
3 4
4 5
5 6
and
1 3
2 3
2 4
4 5
5 6
It's the same. It's essentially a chain. The number doesn't matter. You can draw on paper
Input
Input the group number T of the first row of data (1 ≤ t ≤ 200000). Each group of data has 5 rows, each row is two integers a,b (1 ≤ a,b ≤ 6,a ≤ b)
Data guarantee that the input alkane group is one of the above five
Output
Each group of data, output one line, representing the English name of alkane
Example
Input
2
1 2
2 3
3 4
4 5
5 6
1 4
2 3
3 4
4 5
5 6
Output
n-hexane
3-methylpentane

### Analysis:

A closer look at the graph shows that the five alkanes in the graph are viewed from a tree perspective:
(1) n-hexane has two leaf nodes;
(2) 2,3-dimethylbutane and 2,2-dimethylbutane all have four leaf nodes, but 2,2-dimethylbutane has one node with a degree of 4 (i.e. connected with other four points) and 2,3 has no such node.
(3) The number of leaves connected by 3-methylentane and 2-methylentane with degree 3 is 1 and 2 respectively.
So we have five different alkanes. We can distinguish five alkanes by recording the number of nodes n, the number of nodes r of degree 4 and the number of leaves connected by the points of degree 3.
Create an array c to store the degrees of each node.

### Source code:

```#include<iostream>
#include<cstring>
#include<cmath>
using namespace std;

struct graph
{
int a;
int b;
};

int creatg(graph gra){
// c array is used to store the degree of each point. c is not used
int c = {0,0,0,0,0,0,0};
for(int i = 0 ; i < 5 ; i++){
if(gra.a[i] == 1 || gra.b[i] == 1)
c++;
if(gra.a[i] == 2 || gra.b[i] == 2)
c++;
if(gra.a[i] == 3 || gra.b[i] == 3)
c++;
if(gra.a[i] == 4 || gra.b[i] == 4)
c++;
if(gra.a[i] == 5 || gra.b[i] == 5)
c++;
if(gra.a[i] == 6 || gra.b[i] == 6)
c++;
}

// Count the number of leaf nodes n, the number of nodes r with degree 4, and the number of nodes p with degree 3
int n = 0, r = 0, p = 0;
for(int i = 1 ; i < 7 ; i++){
if(c[i] == 1)
n++;
if(c[i] == 4)
r++;
if(c[i] == 3)
p = i;
}
// Find three first
if(n == 2)
cout << "n-hexane" << endl;
if(n == 4 && r == 0)
cout << "2,3-dimethylbutane" << endl;
if(n == 4 && r == 1)
cout << "2,2-dimethylbutane" << endl;
//  Differentiate between the other two
if(n == 3)
{
// d is used to record the three adjacent nodes of the node with degree 3
int d;
int tag = 0;
for(int i = 0 ; i < 5 ; i++){
if(gra.a[i] == p)
{
d[tag] = gra.b[i];
tag++;
}
if(gra.b[i] == p)
{
d[tag] = gra.a[i];
tag++;
}
};

int u = 0; // u represents the number of leaves in adjacent nodes

for(int i = 0 ; i < 3 ; i++)
{
if(c[d[i]] == 1)
u++;
}
// Distinguish the remaining two
if(u == 1)
cout << "3-methylpentane" << endl;
else
cout << "2-methylpentane" << endl;
}

}

int main(){
graph gra;
int n;
cin >> n;
for(int j = 0 ; j < n ; j++)
{
for(int i = 0 ; i < 5 ; i++)
{
cin >> gra.a[i] >> gra.b[i];
}
creatg(gra);
}

}
```

## B - explode zero (×) and work hard (√)

The real-time evaluation system used in programming thinking assignments and experiments has the characteristics of timely achievement ranking. How is its function realized?
After we have worked hard to finish the procedure that we can't bear to look directly at and submit it, the evaluation system will either return AC or return various other errors. No matter what kind of error method, it will always write a note to you, indicating that you have been cheated here. When you go through thousands of difficulties and finally AC it, it will calculate a general ledger with you, indicating that this problem has been submitted several times in total.
In the long river of years, although you have passed more and more questions, the time you spent passing each question (from the beginning to the time when you passed the question) will be recorded as the trace of your struggle. In particular, for the questions you pass, every time you submit a mistake about this question, you will be counted as a certain unit time penalty. In this way, you may be ahead of others in the number of questions you make, but in the number of people who make the same questions, you may be at a disadvantage in the ranking due to the high penalty time.
For example, there are eight questions (A,B,C,D,E,F,G,H) in an exam. Each person's question has a number mark under the corresponding question number. A negative number indicates the number of times the student has submitted errors on the question, but there is no AC up to now. A positive number indicates the time taken by AC. if a positive number keeps up with a pair of brackets, there is a positive number b in it, It means that the student AC took the time a and submitted b times by mistake. Examples can be found in the sample input and output section below.
Input
The input data includes multiple lines. The first line is the number of common questions n (1 ≤ n ≤ 12) and the unit penalty time m (10 ≤ m ≤ 20). Each line of data after that describes the information of a student. First, the user name of the student (a string of no more than 10 characters) is followed by the score status of all n questions. The description uses the format of the number mark in the problem description, as shown in the table above.
Output
According to the scores of these students, output a real-time ranking. It is obvious that the real-time ranking is first arranged according to the number of AC questions, the most in the first place, and then according to the number of time points, and the least in the first place. If it happens that the first two are equal, it is arranged according to the dictionary order of names, and the small in the first place. Each student takes one line, outputs the name (10 characters wide), the number of questions made (2 characters wide, right aligned) and the time minute (4 characters wide, right aligned). There is a space between the name, the number of questions and the time minute. Data can be output according to the required output format.
Sample Input
8 20
GuGuDong 96 -3 40(3) 0 0 1 -8 0
hrz 107 67 -3 0 0 82 0 0
TT 120(3) 30 10(1) -3 0 47 21(2) -2
OMRailgun 0 -99 -8 0 -666 -10086 0 -9999996
yjq -2 37(2) 13 -1 0 113(2) 79(1) -1
Zjm 0 0 57(5) 0 0 99(3) -7 0
Sample Output
TT 5 348
yjq 4 342
GuGuDong 3 197
hrz 3 256
Zjm 2 316
OMRailgun 0 0

## Analysis:

This problem is similar to the rectangular sorting problem of the first week, which is a kind of multi conditional sorting. The priority is as follows:
(1) Do the questions in descending order
(2) Time spent (including penalty time) in ascending order
(3) Dictionary order of names in ascending order
The sorting function compare is used to achieve sorting.

Source code:

```#include<iostream>
#include<cstring>
using namespace std;

struct student
{
char name;  // ID
int solved;     // A number of questions dropped
int timescore;  // time consuming
}stu;

// Comparison function for sorting
int cmp(int j, int i)
{
// First priority, number of problems solved
if(stu[j].solved < stu[i].solved)
return 1;
else
if(stu[j].solved == stu[i].solved)
// Second priority, time consuming
if(stu[j].timescore > stu[i].timescore)
return 1;
else
if(stu[j].timescore == stu[i].timescore)
// Third priority, name dictionary order
if(strcmp(stu[j].name, stu[i].name) > 0)
return 1;
return 0;
}

// Calculate the function multiplied by 10 to the nth power, which is convenient to convert the number of string saved into int
int e10(int n){
int a = 1;
for(int i = 0 ; i < n ; i++)
{
a *= 10;
}
return a;
}

int main()
{
int n, m;
cin >> n >> m;
int i = 1;
while(cin >> stu[i].name)
{
char a; // Save with string
stu[i].solved = 0;
stu[i].timescore = 0;
// The result of solving n questions circularly
for(int j = 1 ; j <= n ; j++)
{
cin >> a;
if(a != '-' && a > '0')
{
// Problem solving
int tag = 0;
int flags = 0;
stu[i].solved ++;

// Find the length of the first input data
int length = strlen(a);
// Using length to find the first data, processing in reverse order
for(int j = length - 1 ; j >= 0 ; j--)
{
// Partial data conversion
if(a[j] != ')' && a[j] != '(')
{
// computing time
int times = a[j] - '0';
stu[i].timescore += times * e10(tag);
// If the flag is true, it means that this data is the number of failed times. When it should be * 20, because 1 has been added before, just multiply (m-1)
if(flags)
stu[i].timescore += times * e10(tag) * (m - 1);
tag++;
}
// If there are backslashes, the number representing the next processing is the number of failed times, and the flag becomes 1
if(a[j] == ')')
{
flags = 1;
tag = 0;
}
// The flag changes to 0, which means the next data is the normal time
if(a[j] == '(')
{
flags = 0;
tag = 0;
}
}
}
}
// Insert sort, find the location suitable for input data insert
if(i >= 2)
{
for(int j = i - 1 ; j > 0 ; j--)
{
if(cmp(j, i) && !cmp(j - 1 , i))
{
student tmp = stu[i];
for(int k = i - 1 ; k >= j ; k--)
stu[k + 1] = stu[k];
stu[j] = tmp;
break;
}
}
}
i++;
}
// Format output
for(int j = 1 ; j < i ; j++)
{
printf("%-10s ", stu[j].name);
printf("%2d ", stu[j].solved);
printf("%4d\n", stu[j].timescore);
}
}
```

## C - Ruishen playing cards (C++11 is not supported, G + + and C + + compilers try to submit HA)

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
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|
±–±--±–±--±–±--±–±--±–±--±–±--±–+

## Analysis:

We can think of playing cards as A structural card, including pattern and figure. In order to facilitate the operation of this question, we also added A long (holder, 0, 1, 2, 3 for 4 players), and then defined A realnum to convert the number of points represented by the character of figure into int data for easy comparison, where A is represented by 14.
The idea to solve this problem is: record 52 cards in sequence with deck, and the key point of this part is to record the long of each card. After that, we divided the 52 cards into four colors: card club, diamond, spade, heart. Then each decor is sorted.
When outputting, because the size relationship between the colors has been determined, for each player, output plum blossom, square slice, spade, and red peach in turn. Because each color has been arranged in the previous step, the direct output is enough.
This kind of thinking is aimed at the specific questions, and it is not done according to the method of multi conditional sorting.

## Review:

After passing the local sample, it has been WA on VJ. After research, we found the mistake. When I input two character arrays (char b1, b2) with a length of 52, I just adopted the writing method of CIN > > B1 > > B2 directly, which will cause some compilers to treat it as a string, and then add 0 in the last bit, so the last bit will be lost. The solution is to expand the array or use the input method one by one in the following code.

## Source code:

```#include<iostream>
using namespace std;

//(plum C) < Square D) < spade S) < red H
// 2 < 3 < 4 < 5 < 6 < 7 < 8 < 9 < T < J < Q < K < A
//North，East，South，West

struct card{
char pattern; // Flower color
char figure;  // Point
int belong;   // holder
int realnum;  // True value (convert figure to int type)

};

int main(){
char a; // Dealer
while(cin >> a)
{
if(a - '#' == 0)
return 0;
else
{
// Put 52 cards in deck
char b1;
char b2;

for(int i = 0 ; i < 52 ; i++)
{
cin >> b1[i];
}
for(int i = 0 ; i < 52 ; i++)
{
cin >> b2[i];
}

int tag;
if(a == 'N')
tag = 0;
if(a == 'E')
tag = 1;
if(a == 'S')
tag = 2;
if(a == 'W')
tag = 3;

// Declare that deck saves the five cards entered
card deck;
for(int i = 0 ; i < 26 ; i++)
{
deck[i].pattern = b1[2 * i];
deck[i].figure = b1[2 * i + 1];
deck[i].belong = (i + tag) % 4;
}

for(int i = 0 ; i < 26 ; i++)
{
deck[i + 26].pattern = b2[2 * i];
deck[i + 26].figure = b2[2 * i + 1];
deck[i + 26].belong = (i + 2 + tag) % 4;
}

for(int i = 0 ; i < 52 ; i++)
{
if(deck[i].figure - '2' <= 7)
deck[i].realnum = deck[i].figure - '0';
else
{
if(deck[i].figure - 'T' == 0)
deck[i].realnum = 10;
if(deck[i].figure - 'J' == 0)
deck[i].realnum = 11;
if(deck[i].figure - 'Q' == 0)
deck[i].realnum = 12;
if(deck[i].figure - 'K' == 0)
deck[i].realnum = 13;
if(deck[i].figure - 'A' == 0)
deck[i].realnum = 14;
}
}

// It's sorted by decors and the same decors are sorted by size, because the card type has a long sign
// Finally, you can directly press the value of long to get the output
card club;
card diamond;
card heart;

int tag1 = 0, tag2 = 0, tag3 = 0, tag4 = 0;
for(int i = 0 ; i < 52 ; i++)
{

if(deck[i].pattern - 'C' == 0)
{
club[tag1] = deck[i];
tag1++;
}
if(deck[i].pattern - 'D' == 0)
{
diamond[tag2] = deck[i];
tag2++;
}
if(deck[i].pattern - 'S' == 0)
{
tag3++;
}
if(deck[i].pattern - 'H' == 0)
{
heart[tag4] = deck[i];
tag4++;
}
}

// Bubble sort, sort the cards of each suit according to the number of points
for(int i = 0 ; i < 12 ; i++)
{
for(int j = 0 ; j < 12 ; j++)
{
if(club[j].realnum > club[j + 1].realnum)
{
card tmp;
tmp = club[j];
club[j] = club[j + 1];
club[j + 1] = tmp;
}
}
for(int j = 0 ; j < 12 ; j++)
{
if(diamond[j].realnum > diamond[j + 1].realnum)
{
card tmp;
tmp = diamond[j];
diamond[j] = diamond[j + 1];
diamond[j + 1] = tmp;
}
}
for(int j = 0 ; j < 12 ; j++)
{
{
card tmp;
}
}
for(int j = 0 ; j < 12 ; j++)
{
if(heart[j].realnum > heart[j + 1].realnum)
{
card tmp;
tmp = heart[j];
heart[j] = heart[j + 1];
heart[j + 1] = tmp;
}
}
}

// All that's left is the output part. The principle of repetition is to traverse the array of four patterns and find out that the long is 0 / 1 / 2 / 3 of the output respectively
cout << "South player:" << endl;
cout << "+---+---+---+---+---+---+---+---+---+---+---+---+---+" <<endl;
for(int i = 0 ; i < 13 ; i++)
if(club[i].belong == 1)
cout << "|" << club[i].figure << " " << club[i].figure;
for(int i = 0 ; i < 13 ; i++)
if(diamond[i].belong == 1)
cout << "|" << diamond[i].figure << " " << diamond[i].figure;
for(int i = 0 ; i < 13 ; i++)
for(int i = 0 ; i < 13 ; i++)
if(heart[i].belong == 1)
cout << "|" << heart[i].figure << " " << heart[i].figure;
cout << "|" << endl;

for(int i = 0 ; i < 13 ; i++)
if(club[i].belong == 1)
cout << "|" << " " << club[i].pattern << " ";
for(int i = 0 ; i < 13 ; i++)
if(diamond[i].belong == 1)
cout << "|" << " " << diamond[i].pattern << " ";
for(int i = 0 ; i < 13 ; i++)
cout << "|" << " " << spade[i].pattern << " ";
for(int i = 0 ; i < 13 ; i++)
if(heart[i].belong == 1)
cout << "|" << " " << heart[i].pattern << " ";
cout << "|" << endl;

for(int i = 0 ; i < 13 ; i++)
if(club[i].belong == 1)
cout << "|" << club[i].figure << " " << club[i].figure;
for(int i = 0 ; i < 13 ; i++)
if(diamond[i].belong == 1)
cout << "|" << diamond[i].figure << " " << diamond[i].figure;
for(int i = 0 ; i < 13 ; i++)
for(int i = 0 ; i < 13 ; i++)
if(heart[i].belong == 1)
cout << "|" << heart[i].figure << " " << heart[i].figure;
cout << "|" << endl;
cout << "+---+---+---+---+---+---+---+---+---+---+---+---+---+" <<endl;

//
cout << "West player:" << endl;
cout << "+---+---+---+---+---+---+---+---+---+---+---+---+---+" <<endl;
for(int i = 0 ; i < 13 ; i++)
if(club[i].belong == 2)
cout << "|" << club[i].figure << " " << club[i].figure;
for(int i = 0 ; i < 13 ; i++)
if(diamond[i].belong == 2)
cout << "|" << diamond[i].figure << " " << diamond[i].figure;
for(int i = 0 ; i < 13 ; i++)
for(int i = 0 ; i < 13 ; i++)
if(heart[i].belong == 2)
cout << "|" << heart[i].figure << " " << heart[i].figure;
cout << "|" << endl;

for(int i = 0 ; i < 13 ; i++)
if(club[i].belong == 2)
cout << "|" << " " << club[i].pattern << " ";
for(int i = 0 ; i < 13 ; i++)
if(diamond[i].belong == 2)
cout << "|" << " " << diamond[i].pattern << " ";
for(int i = 0 ; i < 13 ; i++)
cout << "|" << " " << spade[i].pattern << " ";
for(int i = 0 ; i < 13 ; i++)
if(heart[i].belong == 2)
cout << "|" << " " << heart[i].pattern << " ";
cout << "|" << endl;

for(int i = 0 ; i < 13 ; i++)
if(club[i].belong == 2)
cout << "|" << club[i].figure << " " << club[i].figure;
for(int i = 0 ; i < 13 ; i++)
if(diamond[i].belong == 2)
cout << "|" << diamond[i].figure << " " << diamond[i].figure;
for(int i = 0 ; i < 13 ; i++)
for(int i = 0 ; i < 13 ; i++)
if(heart[i].belong == 2)
cout << "|" << heart[i].figure << " " << heart[i].figure;
cout << "|" << endl;
cout << "+---+---+---+---+---+---+---+---+---+---+---+---+---+" <<endl;

//
cout << "North player:" << endl;
cout << "+---+---+---+---+---+---+---+---+---+---+---+---+---+" <<endl;
for(int i = 0 ; i < 13 ; i++)
if(club[i].belong == 3)
cout << "|" << club[i].figure << " " << club[i].figure;
for(int i = 0 ; i < 13 ; i++)
if(diamond[i].belong == 3)
cout << "|" << diamond[i].figure << " " << diamond[i].figure;
for(int i = 0 ; i < 13 ; i++)
for(int i = 0 ; i < 13 ; i++)
if(heart[i].belong == 3)
cout << "|" << heart[i].figure << " " << heart[i].figure;
cout << "|" << endl;

for(int i = 0 ; i < 13 ; i++)
if(club[i].belong == 3)
cout << "|" << " " << club[i].pattern << " ";
for(int i = 0 ; i < 13 ; i++)
if(diamond[i].belong == 3)
cout << "|" << " " << diamond[i].pattern << " ";
for(int i = 0 ; i < 13 ; i++)
cout << "|" << " " << spade[i].pattern << " ";
for(int i = 0 ; i < 13 ; i++)
if(heart[i].belong == 3)
cout << "|" << " " << heart[i].pattern << " ";
cout << "|" << endl;

for(int i = 0 ; i < 13 ; i++)
if(club[i].belong == 3)
cout << "|" << club[i].figure << " " << club[i].figure;
for(int i = 0 ; i < 13 ; i++)
if(diamond[i].belong == 3)
cout << "|" << diamond[i].figure << " " << diamond[i].figure;
for(int i = 0 ; i < 13 ; i++)
for(int i = 0 ; i < 13 ; i++)
if(heart[i].belong == 3)
cout << "|" << heart[i].figure << " " << heart[i].figure;
cout << "|" << endl;
cout << "+---+---+---+---+---+---+---+---+---+---+---+---+---+" <<endl;

//
cout << "East player:" << endl;
cout << "+---+---+---+---+---+---+---+---+---+---+---+---+---+" <<endl;
for(int i = 0 ; i < 13 ; i++)
if(club[i].belong == 0)
cout << "|" << club[i].figure << " " << club[i].figure;
for(int i = 0 ; i < 13 ; i++)
if(diamond[i].belong == 0)
cout << "|" << diamond[i].figure << " " << diamond[i].figure;
for(int i = 0 ; i < 13 ; i++)
for(int i = 0 ; i < 13 ; i++)
if(heart[i].belong == 0)
cout << "|" << heart[i].figure << " " << heart[i].figure;
cout << "|" << endl;

for(int i = 0 ; i < 13 ; i++)
if(club[i].belong == 0)
cout << "|" << " " << club[i].pattern << " ";
for(int i = 0 ; i < 13 ; i++)
if(diamond[i].belong == 0)
cout << "|" << " " << diamond[i].pattern << " ";
for(int i = 0 ; i < 13 ; i++)
cout << "|" << " " << spade[i].pattern << " ";
for(int i = 0 ; i < 13 ; i++)
if(heart[i].belong == 0)
cout << "|" << " " << heart[i].pattern << " ";
cout << "|" << endl;

for(int i = 0 ; i < 13 ; i++)
if(club[i].belong == 0)
cout << "|" << club[i].figure << " " << club[i].figure;
for(int i = 0 ; i < 13 ; i++)
if(diamond[i].belong == 0)
cout << "|" << diamond[i].figure << " " << diamond[i].figure;
for(int i = 0 ; i < 13 ; i++)
for(int i = 0 ; i < 13 ; i++)
if(heart[i].belong == 0)
cout << "|" << heart[i].figure << " " << heart[i].figure;
cout << "|" << endl;
cout << "+---+---+---+---+---+---+---+---+---+---+---+---+---+" <<endl;

}
cout << endl;
}
}
```  Published 1 original article, won 1 praise, visited 8

Tags: Programming

Posted on Wed, 04 Mar 2020 01:59:34 -0800 by alen