Delphi 实现刘谦春晚魔术
看了博友的C# 实现刘谦春晚魔术很好,改成了delphi版的。
1 program Project1;
2
3 {$APPTYPE CONSOLE}
4 {$R *.res}
5
6 uses
7 System.SysUtils,
8 System.Classes;
9
10 var
11 list, removeElement: TStringList;
12 i, NameCount, insertIndex, directCount, sexCount: Integer;
13 tmp, element, hiddenEle1, hiddenEle2: String;
14
15 procedure Fun1(NameCount: Integer);
16 begin
17 if NameCount < list.Count then
18 begin
19 for i := 0 to NameCount - 1 do
20 begin
21 element := list[0]; // 获取第0个元素
22 list.Delete(0); // 移除第0个元素
23 list.Add(element); // 将第0个元素添加到最后
24 end;
25
26 end;
27 end;
28
29 procedure Fun2(forCount: Integer);
30 begin
31 // 被删除掉的三张牌
32 removeElement := TStringList.Create;
33 for i := 0 to forCount - 1 do
34 begin
35 removeElement.Add(list[0]);
36 list.Delete(0);
37 end;
38 Writeln(Format('被删除掉的%D张牌:%s', [forCount, removeElement.CommaText]));
39 Writeln('删除之后:' + list.CommaText);
40
41 // 把拿到的三张牌插到中间
42 Randomize;
43 insertIndex := Random(list.Count - 1) + 1; // 生成一个介于第一个和倒数第二个位置之间的随机插入位置
44 Writeln('插入位置:' + insertIndex.ToString);
45 for i := removeElement.Count - 1 downto 0 do
46 begin
47 list.Insert(insertIndex, removeElement[i]);
48 end;
49
50 end;
51
52 procedure Fun3();
53 begin
54 // 藏起来第一张牌
55 hiddenEle1 := list.Strings[0];
56 list.Delete(0);
57 end;
58
59 procedure Fun4(Count: Integer);
60 begin
61 for i := 0 to Count - 1 do
62 begin
63 list.Delete(0);
64 end
65 end;
66
67 procedure Fun5();
68 begin
69 for i := 0 to 6 do
70 begin
71 element := list[0];
72 list.Delete(0);
73 list.Add(element);
74 end;
75 end;
76
77 function Fun6(sexCount: Integer): string;
78 var
79 forCount: Integer;
80 begin
81 forCount := 0;
82 if sexCount = 1 then
83 forCount := 5 // 男生要5次
84 else
85 forCount := 4;
86 for i := 0 to forCount - 1 do
87 begin
88 // 把第一张牌放到数组最后面 (好运留下来)
89 element := list[0];
90 list.Delete(0);
91 list.Add(element);
92
93 // 烦恼丢出去
94 list.Delete(0);
95 end;
96 result := list[0];
97 end;
98
99 begin
100 try
101 try
102 list := TStringList.Create;
103 list.CommaText := 'A,B,C,D,A,B,C,D';
104 Writeln('初始牌组:' + list.CommaText);
105 Writeln('请输入你的名字有几个字:');
106 ReadLn(tmp);
107 NameCount := tmp.ToInteger;
108
109 Fun1(NameCount);
110 Writeln('变化之后:' + list.CommaText);
111
112 Fun2(3);
113 Writeln('插入三张牌后:' + list.CommaText);
114 Fun3();
115 Writeln('藏起来第一张牌后:' + list.CommaText);
116
117 Writeln('北方-1 南方-2 不南不北-3,请输入对应数字:');
118 ReadLn(tmp);
119 directCount := tmp.ToInteger;
120 Fun2(directCount);
121 Writeln('南北方人后:' + list.CommaText);
122
123 Writeln('男-1 女-2,请输入对应数字:');
124 ReadLn(tmp);
125 sexCount := tmp.ToInteger;
126 Fun4(sexCount);
127 Writeln('男女生后:' + list.CommaText);
128
129 Fun5();
130
131 Writeln('见证奇迹后:' + list.CommaText);
132
133 Writeln('开始好运留下了 烦恼丢出去');
134 hiddenEle2 := Fun6(sexCount);
135 Writeln(Format('牌1:%s 牌2:%s', [hiddenEle1, hiddenEle2]));
136
137 ReadLn;
138 except
139 on E: Exception do
140 Writeln(E.ClassName, ': ', E.Message);
141 end;
142
143 finally
144 removeElement.Free;
145 list.Free;
146
147 end;
148
149 end.
Delphi 实现刘谦春晚魔术的更多相关文章
- 亲临现场不是梦,2017央视春晚推出VR直播
自里约奥运会首次试水VR直播 后,用户开始关注这种观影方式,一瞬间VR直播开始流行.就在月初,江苏卫视宣布2017年跨年晚会将进行VR全景直播.当然,央视是绝对不会错过这中潮流方式. 据悉,央视201 ...
- 爱奇艺直播 - 春晚直播业务API架构
小结: 1.服务熔断策略 在网关服务中经常会对后端不同api接口做服务聚合,比如A服务 -> B服务 -> C服务 ,如果C服务出现问题,那么在调用C服务之前需要做熔断.而在设计熔断器的时 ...
- 中软国际首届嘉年华晚会 创新网络年会PK“春晚”
随着新年脚步的来临,各大公司的年会陆续出炉,但是中软国际的首届嘉年华晚会,以创新网络年会和全国八地同步进行的模式,演绎不一样的互联网年会,简直可以PK“春晚”.IT届中最漂亮的美女热舞,程序员中最会唱 ...
- 英语口语练习系列-C34-儿童-谈论物品和人-武陵春
词汇-儿童 child a child favorite game toy regulation breadwinner dominant selfish ancestor custom belief ...
- 晋城6397.7539(薇)xiaojie:晋城哪里有xiaomei
晋城哪里有小姐服务大保健[微信:6397.7539倩儿小妹[晋城叫小姐服务√o服务微信:6397.7539倩儿小妹[晋城叫小姐服务][十微信:6397.7539倩儿小妹][晋城叫小姐包夜服务][十微信 ...
- AutoESL与Xilinx那些人和事
大年三十,看到Xilinx收购AutoESL的新闻, 顿时觉得今年特别喜庆,于是,连春晚也懒得骂了. 本想立即写一篇博文八卦一番, 怎奈亲朋好友饭局不断,一直拖到今天才动笔. 与一年前Xilinx宣布 ...
- 论文keywords和规则匹配的baseline
详细的思路可以参照小论文树立0317 关键词分为以下几类: t/****一些通用的过滤词,这些通用的过滤词可以使用和节目一起出现的词语,结合tf-idf看出来么?*****/ public st ...
- mysql benchmark基准测试
git项目地址: https://github.com/akopytov/sysbench 利用sysbench很容易对mysql做性能基准测试(当然这个工具很强大,除了测试主流数据库性能,还能测试其 ...
- 用自己赚的钱第一次坐飞机 那feel倍儿爽
马年春晚上,歌手大张伟的神曲<倍儿爽>如今已传遍大街小巷.其实,不管人家到底有没有炒作,能让我们这些观众感觉到放松.乐呵,那就是一个成功的春晚节目.而今年,我也如同这歌中唱的一样,活得倍儿 ...
- 所有古诗词的api
服务商:api.getlove.cn 分类:诗词 更新时间:2016-03 如果接口不满足您的要求,您可以联系qq:2265658022购买完整的数据库 免费apikey:56eab527a0facb ...
随机推荐
- 【MicroPython】用 c 添加接口 -- 添加 type
[来源]https://www.eemaker.com/micropython-type.html
- Linux-日期时间-date
- 代码使我头疼之React初学习
前言 开始了,去年(2020)说要学的React,到现在2021年的12月底了,才来实施--(年底警告!年末总结还没开始写!) 不过前端为啥要学React呢?Vue不是很好用吗?Vue确实很好用,并且 ...
- [转帖]在 Linux 上以 All-in-One 模式安装 KubeSphere
https://www.kubesphere.io/zh/docs/v3.4/quick-start/all-in-one-on-linux/ 对于刚接触 KubeSphere 并想快速上手该容器平台 ...
- iPhone 使用类ChatGPT应用的几种方法
iPhone 使用类ChatGPT功能的几种方法 背景 前几天使用edge的wetab的插件给自己的工作带来了很多帮助 尤其是一些基础shell语法以及sql语法, 比使用百度, bing 等搜素引擎 ...
- [转帖]Arm发布CortexX4,功耗可降低40%
https://www.eet-china.com/mp/a224124.html ARM 发布了新一代的移动处理器内核,包括 Cortex-X4.Cortex-A720.Cortex-A520,预计 ...
- DBeaver连接国产信创数据库的步骤
DBeaver连接国产信创数据库的步骤 本次连接使用的数据库类型 1.达梦 2.神通 3.人大金仓 4.瀚高 安装DBeaver 通过官网或者是其他网站下载最新的数据库介质 之后的操作为: 这次不感谢 ...
- echarts的初始化和销毁dispose
容器节点被销毁以及被重建时 假设页面中存在多个标签页, 每个标签页都包含一些图表. 当选中一个标签页的时候,其他标签页的内容在 DOM 中被移除了. 这样,当用户再选中这些标签页的时候,就会发现图表& ...
- vm-storage在新metric占整体1%情况下的写入性能测试
作者:张富春(ahfuzhang),转载时请注明作者和引用链接,谢谢! cnblogs博客 zhihu Github 公众号:一本正经的瞎扯 根据正式环境实际的数据统计,全新的metric占整体的me ...
- 【一文搞定】Linux、Mac、Windows安装Docker与配置教程!
目录 一.Windows 安装 1.1 安装与启用 Hyper-V 1.2 安装 WSL 1.3 Docker Desktop 官方下载 1.4 安装Docker Desktop 二.MacOS 安装 ...