Algorithm


Problem Name: 2 AD-HOC - beecrowd | 1743

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

Automated Checking Machine

 

By Ricardo Anido, UNICAMP BR Brazil

Timelimit: 1

The Internet Computer Parts Company (ICPC) is an on-line shop that sells computer parts. Pairs of in-line electrical connectors are among the most popular parts that ICPC sells. However, they are also one of the parts that are returned more often by unsatisfied customers, because due to errors in packaging the connectors sent to the costumers may not be compatible.

An in-line connector is composed of five connection points, labelled from 1 to 5. Each connection point of a connector can be either a plug or an outlet. We say two connectors are compatible if, for every label, one connection point is a plug and the other connection point is an outlet (in other words, two connectors are compatible if, for every connection point with the same label, a plug and an outlet meet when the two connectors are connected).

The figure below shows examples of two connectors that are compatible and two connectors that are not compatible.

ICPC is introducing a state-of-the-art Automated Checking Machine (ACM), with an optical checker, which will verify whether the two connectors packaged for a customer are indeed compatible. The com- plex and expensive hardware of the ACM is ready, but they need your help to finish the software.

Given the descriptions of a pair of in-line connectors, your task is to determine if the connectors are compatible.

 

Input

 

The first line contains five integers Xi (0 ≤ Xi ≤ 1 for i = 1, 2, . . . , 5), representing the connection points of the first connector in the pair. The second line contains five integers Yi (0 ≤ Yi ≤ 1 for i = 1, 2, . . . , 5), representing the connection points of the second connector. In the input, a 0 represents an outlet an a 1 represents a plug.

 

Output

 

Output a line with a character representing whether the connectors are compatible or not. If they are compatible write the uppercase letter “Y”; otherwise write the uppercase letter “N”.

 

 

 

Input Samples Output Samples

1 1 0 1 0
0 0 1 0 1

Y

 

Code Examples

#1 Code Example with C Programming

Code - C Programming


#include <stdio.h>

int main(void) {
   int a[5], b[5], i;
   int d = 1;

   for (i = 0; i  <  5; ++i) scanf("%d", &a[i]);
   for (i = 0; i  <  5; ++i) scanf("%d", &b[i]);

   for (i = 0; i  <  5; ++i)
      if (!(a[i] ^ b[i])) {
         d = 0;
         break;
      }

   if (d) printf("Y\n");
   else printf("N\n");
   return 0;
}
Copy The Code & Try With Live Editor

Input

x
+
cmd
1 1 0 1 0
0 0 1 0 1

Output

x
+
cmd
Y

#2 Code Example with C++ Programming

Code - C++ Programming


#include <iostream>

using namespace std;

int main(void) {
   int a[5], b[5], i;
   bool d = true;

   for (i = 0; i  <  5; ++i) cin >> a[i];
   for (i = 0; i  <  5; ++i) cin >> b[i];

   for (i = 0; i  <  5; ++i)
      if (!(a[i] xor b[i])) {
         d = false;
         break;
      }

   if (d) cout << "Y";
   else cout << "N";
   cout << endl;
   return 0;
}
Copy The Code & Try With Live Editor

Input

x
+
cmd
1 1 0 1 0
0 0 1 0 1

Output

x
+
cmd
Y

#3 Code Example with Java Programming

Code - Java Programming


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;

public class Main {
    static BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    static PrintWriter out = new PrintWriter(System.out);

    public static void main(String[] args) throws IOException {
        String[] A = in.readLine().split("\\s");
        String[] B = in.readLine().split("\\s");
        for (int i = 0; i  <  5; i++) {
            if (Integer.parseInt(A[i]) + Integer.parseInt(B[i]) != 1) {
                out.println("N");
                out.close();
                break;
            }
        }
        out.println("Y");
        out.close();
    }
}
Copy The Code & Try With Live Editor

Input

x
+
cmd
1 1 0 1 0
0 0 1 0 1

Output

x
+
cmd
Y

#4 Code Example with Javascript Programming

Code - Javascript Programming


const { readFileSync } = require("fs")
const [connectorA, connectorB] = readFileSync("/dev/stdin", "utf8")
	.split("\n", 2)
	.map(line => line.split(" ", 5).map(Number))

const Connector = {
	codes: {
		0: "SOCKET",
		1: "PLUG",
	},

	/**
	 * @param {number[]} cA
	 * @param {number[]} cB
	 */
	isCompatible: function (cA, cB) {
		for (let index in cA)
			if (Connector.codes[cA[index]] === Connector.codes[cB[index]])
				return false

		return true
	}
}

function main() {
	const isCompatible = Connector.isCompatible(connectorA, connectorB)
	console.log(isCompatible ? "Y" : "N")
}

main()
Copy The Code & Try With Live Editor

Input

x
+
cmd
1 1 0 1 0
0 0 1 0 1

Output

x
+
cmd
Y

#5 Code Example with Python Programming

Code - Python Programming


e1 = str(input()).split()
e2 = str(input()).split()
c = True
for i in range(5):
    if e1[i] == e2[i]:
        c = False
        break
print('Y' if c else 'N')
Copy The Code & Try With Live Editor

Input

x
+
cmd
1 1 0 1 0
0 0 1 0 1

Output

x
+
cmd
Y
Advertisements

Demonstration


Previous
#1739 Beecrowd Online Judge Solution 1739 Threebonacci Sequence Solution in C, C++, Java, Js and Python
Next
#1750 Beecrowd Online Judge Solution 1750 Help Cupid Solution in C, C++, Java, Js and Python