当前位置:网站首页>Case - simulated landlords (upgraded version)
Case - simulated landlords (upgraded version)
2022-06-13 05:05:00 【Jason_ LH1024】


package it.com;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.TreeSet;
public class shnegjiPoker {
public static void main(String[] args) {
// establish HashMap, The key is the number , The value is a card
HashMap<Integer, String> hm = new HashMap<>();
// establish ArrayList, Storage number
ArrayList<Integer> array = new ArrayList<>();
// Create a decor array and a point array
String[] colors = {"", "", "", ""};
String[] numbers = {"3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K", "A"};
// from 0 Start to go HashMap It stores the number , And store the corresponding cards , At the same time to ArrayList The number is stored inside
int index = 0;
for (String number : numbers) {
for (String color : colors) {
hm.put(index, color + number);
array.add(index);
index++;
}
}
hm.put(index, " Xiao Wang ");
array.add(index);
index++;
hm.put(index, " King ");
array.add(index);
// Shuffle ( Washing No ), use Collections Of shuffle() Method realization
Collections.shuffle(array);
// Licensing ( It's also a number , In order to ensure that the numbers are sorted , establish TreeSet Collection acceptance )
TreeSet<Integer> funong = new TreeSet<>();
TreeSet<Integer> zhongnong = new TreeSet<>();
TreeSet<Integer> pinnong = new TreeSet<>();
TreeSet<Integer> dipai = new TreeSet<>();
for (int i = 0; i < array.size(); i++) {
int x = array.get(i);
if (i >= array.size() - 3) {
dipai.add(x);
} else if (i % 3 == 0) {
funong.add(x);
} else if (i % 3 == 1) {
zhongnong.add(x);
} else if (i % 3 == 2) {
pinnong.add(x);
}
}
// Call the card reading method
lookPoker(" Rich peasants ",funong,hm);
lookPoker(" Middle peasants ",zhongnong,hm);
lookPoker(" The poor peasants ",pinnong,hm);
lookPoker(" a hand ",dipai,hm);
}
// Define how to look at cards ( Traverse TreeSet aggregate , Get number , To HashMap Set to find the corresponding card )
public static void lookPoker(String name, TreeSet<Integer> ts, HashMap<Integer, String> hm) {
System.out.println(name + " The card is :");
for (Integer key : ts) {
String poker = hm.get(key);
System.out.print(poker + " ");
}
System.out.println();
}
}

边栏推荐
- 17.6 unique_ Lock details
- 关于匿名内部类
- QT signal is automatically associated with the slot
- Chapter 2 process management
- Gradient descent, learning rate
- Spread your wings and soar
- Chapter 18 pagination: Introduction
- Force buckle 92 Reverse linked list II
- Keil uses j-link to burn the code, and an error occurs: Flash download failed - one of the "Cortex-M3" solutions
- Clause 28: understanding reference folding
猜你喜欢
随机推荐
The games that you've tasted
使用EasyDarwin+FFmpeg实现rtsp推流
Clause 30: be familiar with the failure of perfect forwarding
Opencv image storage and reading
Keil uses j-link to burn the code, and an error occurs: Flash download failed - one of the "Cortex-M3" solutions
Binary search and binary answer
C language learning log 10.19
Section 2 - branch and loop statements
Regular expressions in QT
Ruoyi cloud startup tutorial (hand-held graphics)
RT thread console device initialization
Red Treasure Book Reading Notes (continuously updated)
Sub paragraph of Chapter 16
Std:: map insert details
C language learning log 11.7
josephus problem
【转载】C语言内存和字符操作函数大全
OpenCV中的saturate操作(饱和操作)究竟是怎么回事
QT interface rendering style
Wang Dao Chapter II linear table exercises









