#include <stdio.h> int main() { int a,b,c[10],d[10],i,min,k; scanf("%d",&a); for(i=0;i<a;i++) { scanf("%d",&b); for(k=0;k<b;k++) { scanf("%d",&c[k]); } for(k=0;k<b;k++) { if(c[k]!=c[k+1] && c[k]!=c[k+2] && c[k]!=c[k-1] && c[k]!=c[k-2] ) { printf("%d",c[k]); } } printf("\n"); } return 0; }
Problem Description
Given an sorted array A[i] of N positive integers having all the numbers occuring exactly twice, except for one number which will occur only once. Find the number occuring only once.Input
The first line of input contains an integer T denoting the number of test cases. Then T test cases follow.
The first line of each test case contains a positive integer N, denoting the size of the array.
The second line of each test case contains a N positive integers, denoting the elements of the array.
Output
Print out the singly occurring number.
Constraints
1 <= T <= 100
0 < N <= 100
0 <= A[i] <= 100
Test Case 1
Input (stdin)
2 5 1 1 2 5 5 7 2 2 5 5 20 30 30
Expected Output
2 20
Test Case 2
Input (stdin)
2 5 1 1 2 5 5 3 20 30 30
Expected Output
2 20
result is 50%
ReplyDelete