谁是偷盗者解3.cpp

来自「谁是偷盗者问题的源码」· C++ 代码 · 共 49 行

CPP
49 行
字号
// 谁是偷盗者解3.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <iostream>

using namespace std;

int main(int argc, char* argv[])
{
	unsigned short comment[5];
	for(int i=1;i<=4;i++)
	{
		comment[i]=0;
		unsigned short a=0;
		unsigned short b=0;
		cout<<"请输入第"<<i<<"人陈述的2个人:";
		cin>>a>>b;
		if(a==0||b==0)
		{
			comment[i]=15;
		}
		else
		{
			unsigned short c=1;
			comment[i]=(1<<(a-1))|(1<<(b-1));
		}
	}
	unsigned short result=comment[1]&comment[2]&comment[3]&comment[4];
	switch(result)
	{
	case 1:
		cout<<1<<endl;
		break;
	case 2:
		cout<<2<<endl;
		break;
	case 4:
		cout<<3<<endl;
		break;
	case 8:
		cout<<4<<endl;
		break;
	default:
		cout<<"题目错误!"<<endl;
	}
	return 0;
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?