C++二进制(猜你心里想的数0~63)

用一些特殊十进制数的二进制之间是有一定关系的,依照这个关系,就可以制作出这个可以在朋友面前装X的好玩的

#include<bits/stdc++.h>
using namespace std;
int main(){
	int a[8][4],b[8][4],c[8][4],d[8][4],e[8][4],f[8][4];
	int A=32,B=16,C=8,D=4,E=2,F=1;
	for(int i=0;i<8;i++){
		for(int j=0;j<4;j++){
			a[i][j]=A;
			A++;
		}
	}for(int i=0;i<8;i++){
		if(i==4){
			B+=16;
		}for(int j=0;j<4;j++){
			b[i][j]=B;
			B++;
		}
	}for(int i=0;i<8;i++){
		if(i==2 || i==4||i==6){
			C+=8;
		}for(int j=0;j<4;j++){
			c[i][j]=C;
			C++;
		}
	}for(int i=0;i<8;i++){
		D+=4;
		for(int j=0;j<4;j++){
			d[i][j]=D;
			D++;
		}
	}for(int i=0;i<8;i++){
		if(i!=0){
			E+=2;
		}for(int j=0;j<4;j++){
			if(j==2){
				E+=2;
			}
			e[i][j]=E;
			E++;
		}
	}for(int i=0;i<8;i++){
		for(int j=0;j<4;j++){
			f[i][j]=F;
			F+=2;
		}
	}cout<<"游戏规则:"<<endl<<"在心里想一个1到63之间的数,在表里找到你心里想的数所在的表。"<<endl<<"输入表上的编号(A,B,C,D,E,F)"<<endl<<"最后输入‘0’结束输入"<<endl<<"你就可以看到你心里想的数啦"<<endl;
	cout<<"A";
	for(int i=0;i<8;i++){
		cout<<endl;
		for(int j=0;j<4;j++){
			cout<<a[i][j]<<" ";
		}
	}cout<<endl;
	cout<<"B";
	for(int i=0;i<8;i++){
		cout<<endl;
		for(int j=0;j<4;j++){
			cout<<b[i][j]<<" ";
		}
	}cout<<endl;
	cout<<"C";
	for(int i=0;i<8;i++){
		cout<<endl;
		for(int j=0;j<4;j++){
			cout<<c[i][j]<<" ";
		}
	}cout<<endl;
	cout<<"D";
	for(int i=0;i<8;i++){
		cout<<endl;
		for(int j=0;j<4;j++){
			cout<<d[i][j]<<" ";
		}
	}cout<<endl;
	cout<<"E";
	for(int i=0;i<8;i++){
		cout<<endl;
		for(int j=0;j<4;j++){
			cout<<e[i][j]<<" ";
		}
	}cout<<endl;
	cout<<"F";
	for(int i=0;i<8;i++){
		cout<<endl;
		for(int j=0;j<4;j++){
			cout<<f[i][j]<<" ";
		}
	}cout<<endl;
	stack<char>ans;
	char x=1;
	bool y=1;
	while(x!='0'){
		cin>>x;
		if(x!='0'){
			ans.push(x);
		}
	}int ans_ans=0;
	char xy=0;
	while(y!=0){
		if(ans.empty()){
			y=1;
			break;
		}else{
			xy=ans.top();
			ans.pop();
			if(xy=='A'){
				ans_ans+=a[0][0];
			}if(xy=='B'){
				ans_ans+=b[0][0];
			}if(xy=='C'){
				ans_ans+=c[0][0];
			}if(xy=='D'){
				ans_ans+=d[0][0];
			}if(xy=='E'){
				ans_ans+=e[0][0];
			}if(xy=='F'){
				ans_ans+=f[0][0];
			}
		}
	}cout<<ans_ans<<endl;
	return 0;  
}

32 33 34 35        16 17 18 19        8 9 10 11             4 5 6 7                2 3 6 7               1 3 5 7
36 37 38 39        20 21 22 23        12 13 14 15        12 13 14 15        10 11 14 15        9 11 13 15
40 41 42 43        24 25 26 27        24 25 26 27        20 21 22 23        18 19 22 23        17 19 21 23
44 45 46 47        28 29 30 31        28 29 30 31        28 29 30 31        26 27 30 31        25 27 29 31
48 49 50 51        48 49 50 51        40 41 42 43        36 37 38 39        34 35 38 39        33 35 37 39
52 53 54 55        52 53 54 55        44 45 46 47        44 45 46 47        42 43 46 47        41 43 45 47
56 57 58 59        56 57 58 59        56 57 58 59        52 53 54 55        50 51 54 55        49 51 53 55
60 61 62 63        60 61 62 63        60 61 62 63        60 61 62 63        58 59 62 63        57 59 61 63

 最后输出出来就是这个样子的,我们先将每一个表的第一位转为二进制

 32:100000        16:010000        8:001000        4:000100        2:000010        1:000001

当然了我们需要将它们写成六位的而六位最大的二进制数就是63,所以我们的上限就是63我们现在随便挑一个数,比如说17。有17的只有B和F,B和F的开头数字是16和1,将16和1加起来就是17。 

可我们为什么要开头数字相加呢? 

回到之前的二进制,16和1的二进制分别是010000和000001这两个数相加就是17的二进010001 

可它的原理是啥呢? 

32,16,8,4,2,1,这六个数分别是六位二进制的其中仅仅只有一位是1的数(这也突显出了这个数的唯一性),而它所代表的表格,就是六位二进制中那一个位数为1的数,将它所在的列表的第一个数的二进制相加自然就是这个数的二进制啦!

  • 19
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值