First, set a number for each card in the playing card. The numbering rules implemented by the following algorithm are as follows:
In ascending order: 1-13
From small to large, the u square is: 14-26
In ascending order: 27-39
U plum blossom is: 40-52 in ascending order
U King is 53, King is 54
The algorithm is implemented as follows:
U first initializes an array containing 108 numbers according to the above numbering rules
U randomly extracts a number from the array each time and assigns it to an array that stores player data.
The code for implementing this function is as follows:
Copy codeThe Code is as follows:
Import java. util .*;
/**
* Licensing Algorithm Implementation
* Requirement: Send two sub-cards, that is, 108 cards, to four people and leave six cards
*/
Public class Exec {
Public static void main (String [] args ){
// Store an array of 108 cards
Int [] total = new int [108];
// Store the cards of four players
Int [] [] player = new int [4] [25];
// Store the number of remaining cards
Int leftNum = 108;
// Random Number
Int ranNumber;
// Random object
Random random = new Random ();
// Initialize the Array
For (int I = 0; I <total. length; I ++ ){
Total [I] = (I + 1) % 54;
// Process the King number
If (total [I] = 0 ){
Total [I] = 54;
}
}
// Loop Licensing
For (int I = 0; I <25; I ++ ){
// Authorize everyone
For (int j = 0; j <player. length; j ++ ){
// Generate random subscript
RanNumber = random. nextInt (leftNum );
// Licensing
Player [j] [I] = total [ranNumber];
// Move the issued card
Total [ranNumber] = total [leftNum-1];
// Decrease the number of licenses by 1
LeftNum --;
}
}
// Outputs the cards in the player's hands in a loop
For (int I = 0; I <player. length; I ++ ){
For (int j = 0; j <player [I]. length; j ++ ){
System. out. print ("" + player [I] [j]);
}
System. out. println ();
}
// Base card
For (int I = 0; I <8; I ++ ){
System. out. print ("" + total [I]);
}
System. out. println ();
}
}