当前位置:网站首页>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();
}
}

边栏推荐
- RTSP streaming using easydarwin+ffmpeg
- Simple-SR:Best-Buddy GANs for Highly Detailed Image Super-Resolution論文淺析
- Advanced C - Section 2 - pointers
- Metartc4.0 integrated ffmpeg compilation
- About mission planning and improving execution
- OpenCV中的saturate操作(饱和操作)究竟是怎么回事
- Explain the opencv function cv:: add() in detail, and attach sample code and running results of various cases
- Bomb disposal cat
- File descriptorfile description
- 2021TPAMI/图像处理:Exploiting Deep Generative Prior for Versatile Image Restoration and Manipulation
猜你喜欢

RMQ、LCA

Chapter 15 mechanism: Address Translation

使用EasyDarwin+FFmpeg实现rtsp推流

Optocoupler working principle function electric parameter application circuit

Infinite cycle scrolling code Alibaba international station store decoration code base map scrolling black translucent display effect custom content decoration code full screen display

Search DFS and BFS

RTSP streaming using easydarwin+ffmpeg

Recursion and recursion

What is the difference between ROM, ram and flash? SRAM、DRAM、PROM、EPROM、EEPROM

详解OpenCV的函数cv::add(),并附各种情况的示例代码和运行结果
随机推荐
Shell variable learning notes
The problem of flex layout adaptive failure
Dynamic and static libraries
Clause 27: alternatives to overloading with familiar universal reference types
C language learning log 12.5
Embedded hardware: electronic components (1) resistance capacitance inductance
RMQ、LCA
Std:: Map initialization
Simple-SR:Best-Buddy GANs for Highly Detailed Image Super-Resolution論文淺析
Luogu p1036 number selection
Explain the opencv function cv:: add() in detail, and attach sample code and running results of various cases
QT interface rendering style
Metaltc4.0 stable release
Sampo Lock
Redis plus instructions
Implementing the driver registration initcall mechanism on stm32
UNO
【转载】C语言内存和字符操作函数大全
Brick story
What is the difference between ROM, ram and flash? SRAM、DRAM、PROM、EPROM、EEPROM