Algorithm


Problem Name: 2 AD-HOC - beecrowd | 2600

Problem Link: https://www.beecrowd.com.br/judge/en/problems/view/2600

Tustin and His New Die

 

By Aline Regina de Oliveira, IFSULDEMINAS BR Brazil

Timelimit: 1

Tustin, Nike, Jucas and Uill will play a famous RPG game, the T & T (Tatus and Taturanas). Like any good RPG game, the dice is an extremely important part.

T & T is played with six-sided dice. Before they started the game, Tustin went to a store to buy a lucky die, because his old one was devoured by the Temogorgon.

Tustin is very selective, and he want to choose a classic dice. A classic dice is a six-sided dice that has all the numbers from 1 to 6, and the sum of two opposite faces is always 7.

That is, if on one side we have the number 1 we would automatically have the number 6 on the other side.

An example of a classical data is given in the figure below. Your task is to check if the die that Tustin bought is really a classic.

 

Input

 

The first line of input contains a number N that indicates the number of test cases. Each test case consists of six integers Di (0 <= Di <= 105) representing the value of each face of the die. The numbers will be given in three lines, which represent the planning of the data, as in the figure above.

 

Output

 

You should display "SIM" (Yes) if Tustin has purchased a classic dice, and "NAO" (No) otherwise.

 

 

 

Input Sample Output Sample

1
3
1 2 6 5
4

SIM

Code Examples

#1 Code Example with C Programming

Code - C Programming


#include <stdio.h>
#include <stdbool.h>

bool verificaNum(short vet[]);

int main (void)
{

	unsigned short casos, i, j, contador;

	scanf("%hu", &casos);

	while (casos--)
	{
		short dado[6];
		short cmp[] = { 1, 2, 3, 4, 5, 6 };

		for (i = 0; i  <  6; i++)
			scanf("%hu", &dado[i]);

		// Se o dado de Tustin atender a todas as exigências
		// Ele é um dado clássico;
		if (verificaNum(dado) && (dado[0] + dado[5] == 7) && (dado[1] + dado[3] == 7) && (dado[2] + dado[4] == 7))
			printf("SIM\n");
		else
			printf("NAO\n"); 


	}
}

bool verificaNum(short vet[])
{

	unsigned short j, i;
	unsigned short contador;
	short cmp[] = { 1, 2, 3, 4, 5, 6 };

	for (i = 0; i  <  6; i++)
	{

		contador = 0;

		// Verifica se todos os números e 1 a 6 existem no dado de Tustin;
		// Todos os numeros precisam aparecer apenas uma vez no dado;
		for (j = 0; j  <  6; j++)
		{

			if (cmp[i] == vet[j])
				contador++;

			if (contador > 1)
				return false;
		}

		if (contador == 0)
			return false;
	}

	return true;

}
Copy The Code & Try With Live Editor

Input

x
+
cmd
1 3 1 2 6 5 4

Output

x
+
cmd
SIM
Advertisements

Demonstration


Previous
#2592 Beecrowd Online Judge Solution 2592 VaiNaSort Solution in C, C++, Java, Js and Python
Next
#2626 Beecrowd Online Judge Solution 2626 JB6 Team Solution in C, C++, Java, Js and Python