赞
踩
话不多说,先上代码:
#include<bits/stdc++.h> using namespace std; int main() { int a[3],b[3],c[3],t[3]; a[0] = 1; a[1] = 2; a[2] = 3; b[0] = 4; b[1] = 5; b[2] = 6; c[0] = 7; c[1] = 8; c[2] = 9; cout<<"请在 1 2 3 4 5 6 7 8 9 中选一个数,并记在心里\n记完了输ok并按回车\n"; string eee; cin>>eee; cout<<"您选的数在不在"<<a[0]<<" "<<a[1]<<" "<<a[2]<<"中,是输Y加回车,不是输N\n"; cin>>eee; if(eee == "Y"||eee == "y") { t[0] = b[0]; t[1] = b[1]; t[2] = b[2]; b[0] = a[0]; b[1] = a[1]; b[2] = a[2]; a[0] = t[0]; a[1] = t[1]; a[2] = t[2]; } else { cout<<"您选的数在不在"<<b[0]<<" "<<b[1]<<" "<<b[2]<<"中,是输Y加回车,不是输N\n"; cin>>eee; if(eee == "Y"||eee == "y") { } else { cout<<"您选的数在不在"<<c[0]<<" "<<c[1]<<" "<<c[2]<<"中,是输Y加回车,不是输N\n"; cin>>eee; if(eee == "Y"||eee == "y") { t[0] = b[0]; t[1] = b[1]; t[2] = b[2]; b[0] = c[0]; b[1] = c[1]; b[2] = c[2]; c[0] = t[0]; c[1] = t[1]; c[2] = t[2]; } else { cout<<"无效的输入!"; return 0; } } } cout<<"\n\n您选的数在不在"<<a[0]<<" "<<b[0]<<" "<<c[0]<<"中,是输Y加回车,不是输N\n"; cin>>eee; if(eee == "Y"||eee == "y") { cout<<"你选的是"<<b[0]; } else { cout<<"您选的数在不在"<<a[1]<<" "<<b[1]<<" "<<c[1]<<"中,是输Y加回车,不是输N\n"; cin>>eee; if(eee == "Y"||eee == "y") { cout<<"你选的是"<<b[1]; } else { cout<<"你选的是"<<b[2]; } } return 0; }
一个类似于扑克牌魔术,我总结了下原理:
本篇文章将也会发表在黄明礼的博客(我不是黄明礼!)
欢迎转载,转载请标注出处!
喜欢就关注+点赞
您的鼓励是我写文章的动力
赞
踩
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。