PROBLEM LINK:
https://www.codechef.com/problems/GOC101
https://www.codechef.com/GMCD2016/problems/GOC101
Author: https://www.codechef.com/users/pprasadj
Tester: https://www.codechef.com/users/pprasadj
Editorialist: https://www.codechef.com/users/nilesh_dbit
DIFFICULTY:
EASY
PROBLEM:
In a game of a dice, the dice is rolled N times and a sequence of outcomes is generated. In a special case occurrence the outcome stream is generated such that only one number has occurred odd number of times where as others have occurred even number of times. Find out the number which occurred odd number of times.
EXPLANATION:
Ex-oring two numbers give u the number repeating odd number of times.
AUTHOR’S AND TESTER’S SOLUTIONS:
//C program to find the element occurring odd number of times
include <stdio.h>
int main()
{
int ar[100]; // = {2, 2, 3, 5, 5, 4, 4, 4, 4, 5, 5, 6, 3, 3, 3, 6, 6};
int n; //= sizeof(ar)/sizeof(ar[0]);
int res=0, i;
scanf("%d", &n);
for(i=0; i<n; i++)
{
scanf("%d",&ar[i]);
}
// oddnum = getOddOccurrence(arin, n);
for (i=0; i<n; i++)
{
res = res ^ ar[i];
// printf("\n %d", ar[i]);
}
if (res == 0)
{
printf("evennumber");
}
else
printf("%d",res);
return 0;
}