Wednesday, March 29, 2017

Chef and Dolls

Chef is fan of pairs and he likes all things that come in pairs. He even has a doll collection in which all dolls have paired. One day while going through his collection he found that there are odd number of dolls. Someone had stolen a doll!!!
Help chef find which type of doll is missing/

Input
The first line contains the number of test cases.
Second line of the input contains the number of elements in the array.
The next n lines are the types of each doll that is left.

Output
Find the type of doll that doesn't have a pair

Constraints
1<=T<=10
1<=N<=100000 (10^5)
1<=ti<=100000


#include <stdio.h>
int main()
{   int i,j,c,z,y,x[100000],k,a[100000],b,n,m,t;
    scanf("%d",&t);
    for(i=0;i<t;i++)
    {   scanf("%d",&n);
        for(j=0;j<n;j++)
            scanf("%d",&a[j]);
        y=0;
        for(j=0;j<n;j++)
        {   b=a[j];
            c=0;
            for(m=0;m<n;m++)
                        if(a[m]==b)
                            c++;
            if(c%2!=0)
            {   for(z=0;z<=y;z++)
                    if(x[z]==b)
                        break;
                    else
                        printf("%d\n",b);
                x[y]=b;
            }
        }
    }
    return 0;
}

No comments:

Post a Comment