[Solved] Best Couple Event with Java, C++, Python

Best Couple Event: “Shades” Television Channel organizes a fun-filled event named “Best Couple 2017”, where in married couples would be invited and given many tasks and activities. Based on some criteria decided by the jury, a best couple will be chosen.
NĀ couples registered for the event and each couple was given a registration number(it may repeat). One specific couple’s registration Id got missed. The event coordinators wanted your help in finding the missing Id.
Write a program which takes an array of registration numbers as input and outputs the missing registration Id.

Input Format:
First line of the input contains the number of couples N who registered for the event. Assume that the maximum value for N as 50.
Second line of input contains N registration Id of each of the couple, separated by a space.

Output Format:
Output in a single line the missing registration Id.
Refer sample input and output for formatting specifications.

Sample Input 1:
3
1 2 1

Sample Output 1:
2

Sample Input 2:
5
1 1 2 2 3

Sample Output 2:
3

Solution

import java.util.*;

class Main 
{


	public static void main(String args[]) {

		Scanner in = new Scanner(System.in);

		int n = in.nextInt();

		int a[]=new int[n];

		int res=0;
		//sauravhathi
		for(int i=0;i<n;i++) {

			a[i]=in.nextInt();

			res=res^a[i];

		}

		System.out.println(res);

	}


}
#include <bits/stdc++.h>
using namespace std;

int main()
{
    int N;
    //sauravhathi
    cin >> N;
    int array[N];
    for (int i = 0; i < N; i++)
    {
        cin >> array[i];
    }
    int c = 0;
    sort(array, array + N);
    int i = 0;
    while (i < N)
    {
        c = 1;
        while (i < N - 1 && array[i] == array[i + 1])
        {
            c++;
            i++;
            //sauravhathi
        }
        if (c == 1)
        {
            cout << array[i] << " ";
        }
        i++;
    }
    return 0;
    //sauravhathi
}
n = int(input())
a = list(map(int, input().split()))
res = 0
for i in a:
#sauravhathi
    res = res ^ i
print(res)

Happy Learning – If you require any further information, feel free to contact me.

Share your love
Saurav Hathi

Saurav Hathi

I'm currently studying Bachelor of Computer Science at Lovely Professional University in Punjab.

šŸ“Œ Nodejs and Android šŸ˜Ž
šŸ“Œ Java

Articles: 444

Leave a Reply

Your email address will not be published. Required fields are marked *