Header Ads Widget

Determining numbers

Problem:-

You are given an array of integers. The special property of the array is that exactly two different elements occur once while other elements occur twice.
You are required to determine those two elements.
Input format
  • First line: Integer N denoting the number of elements in the array
  • Second line: N space-separated integers denoting the values in the array
Output format
Print two space-separated integers that occur once in the array in ascending order.
Constraints
1N106
1Ai106, where Ai denotes the ith element in the array
SAMPLE INPUT
 
8
1 2 3 4 5 5 3 4
SAMPLE OUTPUT
 
1 2
Explanation
The numbers other than 1 and 2 occur twice, hence, the answer is 1 and 2.
Time Limit:1.0 sec(s) for each input file.
Memory Limit:256 MB
Source Limit:1024 KB

solution:-

#include<stdio.h>
void main()
{
    long int a[1000000],i,j;
    int s=0,k=0,b[4],n;
    scanf("%d",&n);
    for(i=0;i<=n-1;i++)
     scanf("%ld",&a[i]);
    for(i=0;i<=n-1;i++)
    {
        if(a[i]==a[i+1])
        {
         s=s+1;
         i++;
        }
if(s==0)
        {
            b[k]=a[i];
            k++;
        }
        s=0;
    }
    if(b[0]>b[1])
     printf("%d %d",b[1],b[0]);
    else
     printf("%d %d",b[0],b[1]);
}