P8467 C++ 求救 20分
查看原帖
P8467 C++ 求救 20分
507366
文梓铭Johnson楼主2023/1/15 20:40
#include <iostream>
#include <algorithm>
using namespace std;

int zc[5];//暂存数组 
int tr[6];//操作数组

bool chk()
{
	for(int i = 0;i <= 9;i++)//遍历0~9 
	{
		for(int j = 1;j <= 4;j++)//copy 
		{
			tr[j] = zc[j];
		} 
		tr[5] = i;
		sort(tr+1,tr+5+1);//排序 
		//三种符合【好的】的排序后的样子
		if(tr[1] + 1 == tr[2] && tr[2] + 1 == tr[3] && tr[4] == tr[5])
		{
			return true;
		}
		else if(tr[1] == tr[2] && tr[3] + 1 == tr[4] && tr[4] + 1 ==tr[5])
		{
			return true;
		}
		else if(tr[1] + 1 == tr[2] && tr[3] == tr[4] && tr[4] + 1 == tr[5])
		{
			return true;
		}
	}
	return false;//硬是凑不出一种符合的条件
}

int main()
{
	int t;//循环次数times 
	cin >> t;
	for(int i = 1;i <= t;i++)
	{
		for(int j = 1;j <= 4;j++)
		{
			cin >> zc[j];
		}
		if(chk())//判断
		{
			cout << 1; 
		}
		else
		{
			cout << 0;
		}
		cout << endl;
	}
	return 0;
} 

代码如上,20分。 1:AC 2:WA 3:WA 4:WA 5:WA 望大神指导。

2023/1/15 20:40
加载中...