2024春晚刘谦魔术揭秘!
魔术步骤
- 任意4张扑克牌,叠在一起对半撕开,再叠在一起
- 名字有几个字,就把几张扑克,依次放到最下面
- 再将最上面3张,插到剩下扑克牌的中间任意位置
- 拿出最上面一张扑克牌藏起来
- 任意拿出一张、两张或三张扑克牌,再插到剩下扑克牌的中间任意位置
- 如果是男生拿一张,如果是女生拿两张,扔出去
- 见证奇迹的时刻,每说一个字,拿一张扑克放到最下面
- 好运留下来,烦恼抛出去。每说一句话,操作一次。依次一张留下,一张抛出去,留下的依次放到最下面
魔术揭秘
代码实现
pythen
# 2024春晚刘谦纸牌魔术
# Auther: 浙江技术选考高手(微信公众号)
# https://mp.weixin.qq.com/s/_MTU85BNW5Z2LnQNFUbjeg
import random
q=[]
head=tail=0 #创建队列q
while len(q) !=4: #随机生成4张牌
num=random.randint(1,13)
if num not in q:
q.append(num)
tail=tail+1
print(f"随机抽4张牌,分别是{q}")
random.shuffle(q)
print(f"打乱顺序,当前牌池是{q}")
for i in range(4):
q.append(q[i])
tail=tail+1
print(f"对折后撕开,当前牌池是{q}")
#输入当前信息
name=input("请输入你的姓名")
sex=input("请输入你的性别")
print(f"当前名字长度是{len(name)}")
for i in range(len(name)):
q.append(q[head])
head+=1
tail+=1
print(f"按照名字移动后,当前牌池是{q[head:tail]}")
p=[] #
for i in range(3):
p.append(q[head])
head+=1
s=tail-head
for i in range(s//2):
q.append(q[head])
head+=1
tail+=1
for i in range(len(p)):
q.append(p[i])
tail+=1
for i in range(s-s//2):
q.append(q[head])
head+=1
tail+=1
print(f"取三张牌放中间后,当前牌池是{q[head:tail]}")
key=q[head]
head+=1 #第一张藏好,放在key中
print(f"藏好的牌为{key},当前牌池是{q[head:tail]}")
k=random.randint(1,3)
print(f"南方人取1张牌放中间,北方人取2张牌放中间,其他取3张牌放中间")
print(f"随机取{k}张放中间")
p=[] #
for i in range(k):
p.append(q[head])
head+=1
s=tail-head
for i in range(s//2):
q.append(q[head])
head+=1
tail+=1
for i in range(len(p)):
q.append(p[i])
tail+=1
for i in range(s-s//2):
q.append(q[head])
head+=1
tail+=1
print(f"当前牌池是{q[head:tail]}")
if sex == "男":
head+=1
else:
head+=2
print(f"性别是{sex},丢掉了牌之后当前牌池是{q[head:tail]}")
print(f"见证奇迹的时刻")
print(f"把第1张牌放末尾7次")
for i in range(7):
q.append(q[head])
head+=1
tail+=1
print(f"当前牌池是{q[head:tail]}")
print(f"好运留下来,烦恼全扔掉!")
print(f"把第1张牌放末尾,第二张牌扔掉。")
while head+1 != tail:
q.append(q[head])
head+=1
tail+=1
q.append(q[head])
head+=1
print(f"藏好的牌为{key},当前牌池是{q[head:tail]}")
c++
#include<bits/stdc++.h>
using namespace std;
/*
Author: XiaoLe_MC
complete time: 2024/2/11/0:25
*/
bool data1;
vector<int> G;
map<int, string> Gk;
map<int, bool> mp;
string name, gender;
int cn;
inline string gostr(int a){
int kk = a/13;
string rt;
switch(kk){
case 0:
rt = "spade" + to_string(a%13 + 1);
return rt;
case 1:
rt = "heart" + to_string(a%13 + 1);
return rt;
case 2:
rt = "clubs" + to_string(a%13 + 1);
return rt;
default:
rt = "diamond" + to_string(a%13 + 1);
return rt;
}
}
int main(){
printf("Now, we are going to start the magic trick shown by Liu Qian in the 2024 Spring Festival Gala\nNow start to draw your card\n");
srand(time(0));
for(int i=1; i<=4; ++i){
int k = rand()%54 + 1;
while(mp[k]) int k = rand()%54 + 1;
mp[k] = true;
if(k == 53 || k == 54){
if(k&1){
Gk[k] = "blackjack";
printf("Your %dth card is blackjack\n", i);
G.push_back(k);
}
else{
Gk[k] = "redjack";
printf("Your %dth card is redjack\n", i);
G.push_back(k);
}
} else{
Gk[k] = gostr(k);
printf("Your %dth card is %s\n", i, Gk[k].c_str());
G.push_back(k);
}
}
printf("\nStep 1: Tear the cards in half and fold them back together\n");
for(int i=0; i<4; ++i) G.push_back(G[i]);
printf("Now, the cards in your hand: ");
for(int i=0; i<8; ++i) printf("%s ", Gk[G[i]].c_str());
printf("\n\nStep 2, Please enter your name (in English): ");
cin >> name; // scanf("%s", name);
int len = name.size();
printf("Your name has %d letters, so put %d cards under the stack!\n", len, len);
for(int i=0; i<len; ++i) G.push_back(G[i]);
G.erase(G.begin(), G.begin() + len);
printf("Now, the cards in your hand: ");
for(int i=0; i<8; ++i) printf("%s ", Gk[G[i]].c_str());
printf("\n\nStep 3: Randomly place the first three cards of your stack into the middle of the stack.\n");
for(int i=0; i<3; ++i){
int k = rand()%(4+i) + 4 - i;
G.insert(G.begin() + k, G[0]);
G.erase(G.begin(), G.begin()+1);
}
printf("Now, the cards in your hand: ");
for(int i=0; i<8; ++i) printf("%s ", Gk[G[i]].c_str());
printf("\n\nStep 4: Take out the first card of your stack and use it as your lucky card.\n");
printf("Your lucky card is %s\n", Gk[G[0]].c_str());
G.erase(G.begin(), G.begin()+1);
printf("Now, the cards in your hand: ");
for(int i=0; i<7; ++i) printf("%s ", Gk[G[i]].c_str());
printf("\n\nStep 5: Randomly place the first several cards of your stack into the middle of the stack.\nPlease enter the number of cards you wish to place(1 to 3): ");
scanf("%d", &cn);
for(int i=0; i<cn; ++i){
int k = rand()%5 + 2;
G.insert(G.begin() + k, G[0]);
G.erase(G.begin(), G.begin()+1);
}
printf("Now, the cards in your hand: ");
for(int i=0; i<7; ++i) printf("%s ", Gk[G[i]].c_str());
printf("\n\nStep 6: Enter your gender (male or female):");
cin >> gender;
if(gender == "male"){
printf("You are a male, so you discard the top 1 card.\n");
G.erase(G.begin(), G.begin()+1);
} else{
printf("You are a female, so you discard the top 2 card.\n");
G.erase(G.begin(), G.begin()+2);
}
printf("Now, the cards in your hand: ");
for(int i=0; i<G.size(); ++i) printf("%s ", Gk[G[i]].c_str());
printf("\n\nStep 7, \"Time to Witness a Miracle.\" For each word, take a poker and put it at the bottom.\n");
for(int i=0; i<7; ++i){
G.push_back(G[0]);
G.erase(G.begin(), G.begin()+1);
}
printf("Now, the cards in your hand: ");
for(int i=0; i<G.size(); ++i) printf("%s ", Gk[G[i]].c_str());
printf("\n\nStep 8: \"Good luck stays\", \"Worries are thrown out\". Operate once for each word. In order one stays, one throws out, and the ones that stay go to the bottom in order.\n");
printf("Until only the last card remains. Let's go!\n");
while(G.size() > 1){
printf("Good luck stays!\n");
G.push_back(G[0]);
G.erase(G.begin(), G.begin()+1);
printf("Now, the cards in your hand: ");
for(int i=0; i<G.size(); ++i) printf("%s ", Gk[G[i]].c_str());
printf("\nWorries are thrown out!\n");
G.erase(G.begin(), G.begin()+1);
printf("Now, the cards in your hand: ");
for(int i=0; i<G.size(); ++i) printf("%s ", Gk[G[i]].c_str());
printf("\n");
}
printf("What a coincidence that your lucky deck is also this one!\n");
return 0;
}
标签:rt,head,刘谦,range,2024,tail,print,揭秘,append
From: https://www.cnblogs.com/xiaolemc/p/18013136