Programming Languages Problem Code: PROGLANG Codechef solutions

Programming Languages Problem Code: PROGLANG
Submit

Read problem statements in MandarinBengaliRussian, and Vietnamese as well.

Chef is a software developer, so he has to switch between different languages sometimes. Each programming language has some features, which are represented by integers here.

Currently, Chef has to use a language with two given features A and B. He has two options --- switching to a language with two features A1 and B1, or to a language with two features A2 and B2. All four features of these two languages are pairwise distinct.

Tell Chef whether he can use the first language, the second language or neither of these languages (if no single language has all the required features).

Input Format

  • The first line of the input contains a single integer T denoting the number of test cases. The description of T test cases follows.
  • The first and only line of each test case contains six space-separated integers A,B,A1,B1,A2,B2.

Output Format

For each test case, print a single line containing the integer 1 if Chef should switch to the first language, or 2 if Chef should switch to the second language, or 0 if Chef cannot switch to either language.

Constraints

  • 1T288
  • 1A,B,A1,B1,A2,B24
  • A,B are distinct
  • A1,B1,A2,B2 are pairwise distinct

Subtasks

Subtask #1 (100 points): original constraints

Sample Input 1 

3
1 2 2 1 3 4
3 4 2 1 4 3
1 2 1 3 2 4

Sample Output 1 

1
2
0

Explanation

Example case 1: The first language has the required features --- features 1 and 2.

Example case 2: The second language has the required features --- features 3 and 4.

Example case 3: Neither language has both features 1 and 2.












Solution in C #include <stdio.h> int main(void) { int t; scanf("%d",&t); while(t--){ int a[6]; for(int i=0;i<=5;i++){ scanf("%d",&a[i]); } if((a[0]==a[2]||a[0]==a[3])&&(a[1]==a[2]||a[1]==a[3])) printf("1\n"); else if((a[0]==a[4]||a[0]==a[5])&&(a[1]==a[4]||a[1]==a[5])) printf("2\n"); else printf("0\n"); } } Solution in C++ #include <bits/stdc++.h>
using namespace std;
#define ll long long
void solve();
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("error.txt", "w", stderr);
freopen("output.txt", "w", stdout);
#endif
int t=1;
/*is Single Test case?*/
cin >> t;
// t=1;
//single test case -= Delete if t testCases =-
while (t--) {
solve();
cout << "\n";
}
cerr << "time taken : " << (float)clock() / CLOCKS_PER_SEC << " secs" << endl;
int z;
cin>>z;
return 0;
}
void solve()
{
int a,b,a1,b1,a2,b2;
cin>>a>>b>>a1>>b1>>a2>>b2;
if((a==a1 && b==b1) || (a==b1 && b==a1)) cout<<"1";
else if((a==a2 && b==b2) || (a==b2 && b==a2)) cout<<"2";
else cout<<"0";
}
using namespace std; 
#define ll long long 
void solve(); 
int main() 
{ 
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL); 
   
#ifndef ONLINE_JUDGE 
    freopen("input.txt", "r", stdin); 
    freopen("error.txt", "w", stderr); 
    freopen("output.txt", "w", stdout); 
#endif 
   
    int t=1; 
    /*is Single Test case?*/ 
     
    cin >> t; 
     
    // t=1;  
     
    //single test case  -= Delete if t testCases =- 
     
    while (t--) { 
        solve(); 
        cout << "\n"; 
    } 
   
    cerr << "time taken : " << (float)clock() / CLOCKS_PER_SEC << " secs" << endl; 
    int z; 
    cin>>z; 
    return 0; 
} 
void solve() 
{ 
    int a,b,a1,b1,a2,b2; 
    cin>>a>>b>>a1>>b1>>a2>>b2; 
    if((a==a1 && b==b1) || (a==b1 && b==a1)) cout<<"1"; 
    else if((a==a2 && b==b2) || (a==b2 && b==a2)) cout<<"2"; 
    else cout<<"0"; 
}

Comments