Valid Pair Codechef Solution

Hello coders, today we are going to solve Valid Pair Codechef Solution Which is part of Codechef.

Valid Pair Codechef Solution
Valid Pair Codechef Solution

Problem

Chef has to wear two socks which have the same colour. Help Chef find out if that is possible or not.

Chef has three socks in his drawer. Each sock has one of 10 possible colours, which are represented by integers between 1 and 10. Specifically, the colours of the socks are AB, and C.

Input

The first and only line of the input contains three space-separated integers AB and C.

Output

Print a single line containing the string “YES” if it is possible for Chef to wear two socks with the same colour or “NO” if it is impossible (without quotes).

You may print each character of each string in uppercase or lowercase (for example, the strings “yEs”, “yes”, “Yes” and “YES” will all be treated as identical).

Constraints

  • 1 <= A, B, C <= 10

Subtasks

Subtask #1 (100 points): Original Constraints 

Example Input 1

5 4 3

Example Output 1

NO

Explanation

Since there are no two socks with the same colour, Chef cannot wear a pair of socks with the same colour.

Example Input 2

5 5 5

Example Output 2 

YES

Explanation 

Since all three socks have the same colour, Chef can wear a pair of socks with the same colour.

Valid Pair Codechef Solution in Python

a, b, c = map(int, input().split())
if a == b:
    print("YES")
elif b == c:
    print("YES")
elif a == c:
    print("YES")
elif a == b == c:
    print("YES")
else:
    print("NO")

Valid Pair Codechef Solution in CPP

#include <iostream>
#include<bits/stdc++.h>
using namespace std;
int main() {
	int a[3],k=0;
	cin>>a[0]>>a[1]>>a[2];
	sort(a,a+3);
	for(int i=0;i<2;i++)
	{
	    if (a[i]==a[i+1])
	    {
	    cout<<"yes"<<endl;
	    k++;
	    break;
	    }
	}
	if (k==0)
	cout<<"No"<<endl;
	return 0;
}

Valid Pair Codechef Solution in JAVA

import java.util.*;
import java.lang.*;
import java.io.*;
/* Name of the class has to be "Main" only if the class is public. */
class Codechef
{
 public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        int a = input.nextInt();
        int b = input.nextInt();
        int c = input.nextInt();
        System.out.println(solve(a,b,c));
    }
    public static String solve(int a, int b, int c) {
        if (a == b || a == c || b == c) {
            return "Yes";
        } else {
            return "No";
        }
    }
}

Disclaimer: The above Problem (Valid Pair) is generated by CodeChef but the solution is provided by Chase2learn.This tutorial is only for Educational and Learning purpose.

Sharing Is Caring

Leave a Comment