Simulation of the landlord shuffle, licensing (containing sort and unordered)

Source: Internet
Author: User
Tags shuffle

Not sorted by:

Package Cn.idcast5;import java.util.arraylist;import java.util.collections;//simulation bucket landlord Shuffle licensing//analysis//a create a card box//b pack//c shuffle//d licensing//e public class Shiyue31 {public static void main (string[] Args) {//create a card box arraylist<string> array = new Arrayli st<string> ()////black Peach a, spades 2, spades 3......//red peach a......//square a......//plum a......//define a suit array string[] colors = {"?", "?", "?", "-"};//  Define an array of points string[] numbers = {"A", "2", "3", "4", "5", "6", "7", "8", "9", "ten", "J", "Q", "K"};for (String color:colors) {for (String number:numbers) {array.add (color.concat (number));}} Array.add ("xiao wang"); array.add ("king");//shuffle collections.shuffle (array);//licensing arraylist<string> Zengjiao = new Arraylist<string> (); arraylist<string> Xiajiao = new Arraylist<string> (); arraylist<string> sb = new Arraylist<string> (); arraylist<string> Dipai = new arraylist<string> (); for (int x = 0; x < array.size (); + +) {if (x>=array.s ize ()-3) {dipai.add (array.get (x));} else if (x 3 = = 0) {zengjiao.add (array.get (x));} else if (x 3 = = 1) {xiajiao.add (array.get (x));} else if (x% 3 = = 2) {sb.add (array.get (x));}} See card Lookpoker ("zeng dumplings", zengjiao), lookpoker ("shrimp dumplings", xiajiao), lookpoker ("dumb", sb), lookpoker ("hole cards", dipai);} public static void Lookpoker (string name, arraylist<string> array) {System.out.println (name+ "card is:"); for (string s : Array) {System.out.print (s+ "");} System.out.println ();}}

Sorted by:

Package Cn.idcast5;import Java.util.arraylist;import Java.util.collections;import java.util.hashmap;import java.util.treeset;/* Ideas * A Create a hashmap collection * B Create a ArrayList collection * C create a suit array and an array of points * D from 0 onwards to the HashMap store the number, and store the corresponding card * at the same time toward the Arrayl IST store Number * E Shuffle (wash is number) * F card (the number of the hair is also numbered, in order to ensure that the number is sorted, create TreeSet collection Receive) * G to see the card (traverse treeset collection, get the number, to HashMap collection to find the corresponding Card) */public class S hiyue3102 {public static void main (string[] Args) {//create a HashMap collection hashmap<integer, string> HM = new Hashmap<inte Ger,string> ();//create a ArrayList collection arraylist<integer> array = new arraylist<integer> ();// Create a suit array and array of points string[] colors = {"?", "?", "?", "-"}; string[] numbers = {"3", "4", "5", "6", "7", "8", "9", "ten", "J", "Q", "K", "A", "2"};//starting from 0 int index = 0;for (String Numbe R:numbers) {for (string color:colors) {string poker = color.concat (number);//store numbers in HashMap and store corresponding cards hm.put (index, poker )///to Store the number Array.add (index) at the same time, index + + arraylist;}} Hm.put (index, "xiao wang"); array.add (index); index++;hm.put (index, "king"); array.add (index);//Shuffle (wash is numbered) collections.shuffle (array);//the card (the number of the hair, in order to ensure that the number is sorted, create TreeSet collection received) treeset<integer> Zengjiao = new Treeset<integer> (); treeset<integer> Xiajiao = new Treeset<integer> (); treeset<integer> sb = new Treeset<integer> (); treeset<integer> Dipai = new treeset<integer> (), for (int x=0;x<array.size (); x + +) {if (x>= array.size ( )-3) {dipai.add (array.get (x)),} else if (x%3 ==0) {zengjiao.add (array.get (x)),} else if (x%3 ==1) {xiajiao.add (array.get ( x));} else if (x%3 = = 2) {sb.add (array.get (x));}} See cards (traverse treeset collection, get numbers, find corresponding cards to HashMap Collection) lookpoker ("zeng dumplings", zengjiao,hm), lookpoker ("shrimp dumplings", xiajiao,hm); lookpoker ("stupid", SB , hm); lookpoker ("hole cards", dipai,hm);} Here is the name, the card number, the number corresponding to the card public static void Lookpoker (string name,treeset<integer> ts,hashmap<integer, string > Hm) {System.out.println (name+ "is:"); for (Integer key:ts) {String value = Hm.get (key); System.out.print (value + "");} System.out.println ();}}

  

Simulation of the landlord shuffle, licensing (containing sort and unordered)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.