刘谦龙年春晚魔术模拟

2024-02-10 18:04
文章标签 模拟 魔术 春晚 刘谦龙

本文主要是介绍刘谦龙年春晚魔术模拟,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

守岁共此时

代码

直接贴代码了,异常处理有点问题,正常流程能跑通

package com.yuhan.snginx.util.chunwan;import java.util.*;/*** @author yuhan* @since 2024/02/10*/
public class CWMS {static String[] num = {"A", "2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K"};static String[] style = {"♠️", "♥️", "♣️", "♦️"};static String[] wang = {"大王", "小王"};public static List<String> listPoker = new ArrayList<>(54);public static List<String> choose = new ArrayList<>(4);public static HashMap<Integer, String> map = new HashMap<>();static {map.put(1, "南方");map.put(2, "北方");map.put(3, "二家岗子");}public static List<String> getAllPoker() {for (String string : style) {for (String s : num) {listPoker.add(string + s);}}listPoker.add(Arrays.toString(wang));return listPoker;}public static void choosePoker() {String styleIn, numIn;for (int i = 0; i < 4; i++) {System.out.println("\n请选择花色");Scanner scanner = new Scanner(System.in);styleIn = scanner.nextLine();System.out.println("请选择数字");numIn = scanner.nextLine();System.out.println("是否确认选择 ok or any keys");String sc = scanner.nextLine();if (!Objects.equals(sc, "ok")) {return;}while (Objects.isNull(styleIn) || Objects.isNull(numIn)) {System.out.println("输入错误,请重新输入");}String chPoker = styleIn + numIn;while (!listPoker.contains(chPoker)) {System.out.println("花色非法或不存在的数字");}System.out.println("\n 本次选择" + chPoker);choose.add(chPoker);}System.out.println("你选择的扑克分别为:");choose.forEach(System.out::println);}public static void suffer() {System.out.println("\n 请打乱刚刚选择的牌,按ok键进行 !");Scanner scanner = new Scanner(System.in);if ("ok".equalsIgnoreCase(scanner.nextLine())) {System.out.println("\n洗牌前顺序");choose.forEach(s -> System.out.println(s + " "));Collections.shuffle(choose);System.out.println("\n洗牌后顺序");choose.forEach(s -> System.out.println(s + " "));}}public static List<String> push() {System.out.println("请从中间撕碎扑克,按 ok 撕碎 !");Scanner scanner = new Scanner(System.in);if (!"ok".equalsIgnoreCase(scanner.nextLine())) {System.out.println("不撕就别玩,结束了");return choose;}ArrayList<String> result = new ArrayList<>(choose);for (String s : choose) {String str = s + "副本";result.add(str);}result.forEach(System.out::println);return result;}public static void nameSuffer(List<String> push) {System.out.println("请输入你的姓名,名字有几个字,就将最上面的牌放到最下边几次");Scanner scanner = new Scanner(System.in);String name = scanner.nextLine();if (Objects.isNull(name)) {System.out.println("姓名为空");return;}for (int i = 0; i < name.length(); i++) {String first = push.get(0);push.remove(0);push.add(first);}}public static void magicTime(List<String> push) {String magic = "见证奇迹的时刻";for (int i = 0; i < magic.length(); i++) {String first = push.get(0);push.remove(0);push.add(first);}}public static void suffer_3(List<String> push, boolean region, int regionChoose) {Random random = new Random();if (region) {regionChoose = (regionChoose < 1 || regionChoose > 3) ? 3 : regionChoose;}// 生成3到5之间的随机数int randomNum = region ? random.nextInt(4 + (3 - regionChoose)) : random.nextInt(4);System.out.println(randomNum);ArrayList<String> third = new ArrayList<>();for (int i = 0; i < 3; i++) {third.add(push.get(i));}
//        third.forEach(System.out::println);
//        System.out.println("third");if (!region) {push.remove(0);push.remove(0);push.remove(0);} else {for (int i = 0; i < regionChoose; i++) {push.remove(0);}}//        push.forEach(System.out::println);
//        System.out.println("removed");push.addAll(randomNum + 1, third);}public static String getFirst(List<String> suffered) {return suffered.get(0);}public static int region() {System.out.println("\n 请选择南北方人 ,如果你是南方人请输入 1;如果你是北方人请输入 2; 如果不能确认你是南北方人请输入 3");Scanner scanner = new Scanner(System.in);int i = scanner.nextInt();while (Objects.isNull(map.get(i))) {System.out.println("输入错误,请重新输入 !");i = scanner.nextInt();}System.out.println("你已选择" + map.get(i));return i;}public static void drop(List<String> pushed, int i) {for (int i1 = 0; i1 < i; i1++) {pushed.remove(0);}}public static int chooseSex() {Scanner scanner = new Scanner(System.in);System.out.println("请选择 性别 男:1 女:2");int i = scanner.nextInt();System.out.println(i == 1 ? "男" : "女");return i;}/*** 好运留下来** @param args*/public static void luck(List<String> push) {String first = push.get(0);push.remove(0);System.out.println("好运留下来");push.add(first);System.out.println("烦恼丢出去");push.remove(0);}private static void anyWay(List<String> pushed) {while (pushed.size() > 1) {luck(pushed);}}public static void main(String[] args) {// 获取完整扑克getAllPoker().forEach(t -> System.out.print("   " + t));// 从中选择四张choosePoker();// 打乱suffer();// 撕碎List<String> pushed = push();// namenameSuffer(pushed);// suffer_3suffer_3(pushed, false, 0);// 记住取出的第一张牌String first = getFirst(pushed);// 南北方人选择// 南方北方切牌suffer_3(pushed, true, region());// 男女选择int sex = chooseSex();drop(pushed, sex);// 见证奇迹的时刻magicTime(pushed);// 多来几次anyWay(pushed);// 对比System.out.println("第一张牌" + first);System.out.println("丢完剩下的" + pushed.get(0));}}

这篇关于刘谦龙年春晚魔术模拟的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/697749

相关文章

基于 Java 实现的智能客服聊天工具模拟场景

服务端代码 import java.io.BufferedReader;import java.io.IOException;import java.io.InputStreamReader;import java.io.PrintWriter;import java.net.ServerSocket;import java.net.Socket;public class Serv

价格减免(Lc2288)——模拟

句子 是由若干个单词组成的字符串,单词之间用单个空格分隔,其中每个单词可以包含数字、小写字母、和美元符号 '$' 。如果单词的形式为美元符号后跟着一个非负实数,那么这个单词就表示一个 价格 。 例如 "$100"、"$23" 和 "$6" 表示价格,而 "100"、"$" 和 "$1e5 不是。 给你一个字符串 sentence 表示一个句子和一个整数 discount 。对于每个表示价格的单

模拟木马程序自动运行:Linux下的隐蔽攻击技术

模拟木马程序自动运行:Linux下的隐蔽攻击技术 在网络安全领域,木马程序是一种常见的恶意软件,它能够悄无声息地在受害者的系统中建立后门,为攻击者提供远程访问权限。本文将探讨攻击者如何在Linux系统中模拟木马程序的自动运行,以及他们可能使用的技术手段。 木马自动运行的常见方法 攻击者通常会使用以下几种方法来确保木马在Linux系统中自动运行: 计划任务(Crontab): 攻击者可以通

2023-2024 学年第二学期小学数学六年级期末质量检测模拟(制作:王胤皓)(90分钟)

word效果预览: 一、我会填 1. 1.\hspace{0.5em} 1. 一个多位数,亿位上是次小的素数,千位上是最小的质数的立方,十万位是 10 10 10 和 15 15 15 的最大公约数,万位是最小的合数,十位上的数既不是质数也不是合数,这个数是 ( \hspace{4em} ),约等于 ( \hspace{1em} ) 万 2. 2.\hspace{0.5em} 2.

java实训 | 低配版模拟火车订票系统

代码:  import javax.swing.*;import java.awt.*;import java.awt.event.ActionEvent;import java.util.ArrayList;import java.util.List;public class TrainBookingSystem {private JFrame frame;private JPanel

phpmailer 邮件模拟注册验正

下载phpmailer类 我本次的实验用的是版本 5.2.9 下载后解压提取文件class.smtp.php class.phpmailer.php PHPMailerAutoload.php 放在phpmailer目录里 1.链接数据库 conn.php   $conn=mysql_connect("localhost","root","");    if(!$conn){

C++11 标准库头文件模拟实现

系列文章目录 文章目录 系列文章目录前言● 智能指针模板● Vector1. 简单版本2. X 总结 前言 暂不考虑支持多线程 常用STL的简单实现,主要内容百行左右完成,意在理解STL的原理 ● 智能指针模板 SharedPtr #include <assert.h>#include <atomic>template <class T>class S

模拟算法讲解

模拟算法是一种基于实际情况模拟的算法,通过模拟现实世界中的系统或过程,来研究它们的性质和行为。模拟算法可以用于解决各种问题,包括物理模拟、经济模拟、社会模拟等。 模拟算法的基本步骤包括: 定义问题:明确需要模拟的系统或过程,并确定模拟的目标和约束条件。建立模型:根据问题定义,设计合适的模型来描述系统或过程的组成和行为。收集数据:收集和整理与模型相关的数据,包括初始状态和影响模拟结果的参数。

biostar handbook|如何模拟NGS测序结果

如何用软件模拟NGS数据 为了评价一个工具的性能,通常我们都需要先模拟一批数据。这样相当于有了参考答案,才能检查工具的实际表现情况。因此对于我们而言,面对一个新的功能,可以先用模拟的数据测试下不同工具的优缺点。有如下几个工具值得推荐一下: 'wgsim/dwgsim': 从全基因组中获取测序reads'msbar': EMBOSS其中一个工具,能够从单个序列中模拟随机突变'biosed': E

AIGC时代算法工程师的面试秘籍(2024.5.13-5.26第十四式) |【三年面试五年模拟】

写在前面 【三年面试五年模拟】旨在整理&挖掘AI算法工程师在实习/校招/社招时所需的干货知识点与面试方法,力求让读者在获得心仪offer的同时,增强技术基本面。也欢迎大家提出宝贵的优化建议,一起交流学习💪 欢迎大家关注Rocky的公众号:WeThinkIn 欢迎大家关注Rocky的知乎:Rocky Ding AIGC算法工程师面试面经秘籍分享:WeThinkIn/Interview-