First, set a number for each card in the playing card. Algorithm The numbering rules 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.
To achieve this function Code As follows:
Copy code The 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 ();
}
}