Combinational Logic

PROBLEM :

Construct a 6 input gate which performs the following logical operation:
 (not(A)).B + C.D +E.(not(F))
where A, B, C, D, E and F are the inputs to the 6 input gate.



Input:
The first line of input takes the number of test cases, T. Then T test cases follow. Each test case takes 6 space separated integers denoting the inputs to the 6 input gate, A, B, C, D,E and F.

Note: the inputs can be either 1's or 0's.


Output:
Print the output of the 6 input gate for each test case on a new line.


Constraints:
1<=T<=100
0<=A,B,C,D<=1


Example:
Input:
3
1 1 0 0 1 1
1 1 1 1 1 1
1 0 0 1 1 1

Output:
0
1
0

Explanation:

In the first test case, A=1, B=1, C=0, D=0, E=1, F=1 so (not(A)).B + C.D +E.(not(F)) = 0.1 + 0.0 + 1.0 = 0 + 0 + 0 = 0

In the second test case, A=1, B=1, C=1, D=1, E=1, F=1. so (not(A)).B + C.D +E.(not(F)) = 0.1 + 1.1 + 1.0 = 0 + 1 + 0 = 1

In the third test case, A=1, B=0, C=0, D=1, E=1, F=1. so (not(A)).B + C.D +E.(not(F)) = 0.0 + 0.1 + 1.0 = 0 + 0 + 0 = 0

--------------------------------------------------------------------------------
SIMPLE c++ IMPLEMENTATION :
--------------------------------------------------------------------------------

#include<iostream>
using namespace std;
int result(int ,int ,int ,int ,int ,int ) ;
int main()
 {
int t ;
int a,b,c,d,e,f ;
cin>>t ;
while(t--)
{
   cin>>a>>b>>c>>d>>e>>f ;
   cout<<result(a,b,c,d,e,f) ;
   cout<<endl ;
}
return 0;
}

int result(int a,int b,int c,int d,int e,int f)
{
    a=!a ;
    f=!f ;
   
    return a&&b||c&&d||e&&f ;
}

---------------------------------------------------------------------------------

Comments

Popular posts from this blog

Count ways to N'th Stair(Order does not matter)

Replace all ‘0’ with ‘5’ in an input Integer

Chocolate Distribution Problem

Remove characters from the first string which are present in the second string

Primality Test ( CodeChef Problem code: PRB01 )