GOC 101 "Rolling of Dice" - Editorial

PROBLEM LINK:

GOC101 Problem - CodeChef

CodeChef: Practical coding for everyone

Author: pprasadj | CodeChef User Profile for Prasad Padalkar | CodeChef

Tester: pprasadj | CodeChef User Profile for Prasad Padalkar | CodeChef

Editorialist: nilesh_dbit | CodeChef User Profile for Nilesh | CodeChef

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; 
}

i = input()
for j in range(len(i)):
count=0
for k in i:
if i[j]==k:
count+=1
if count%2==1:
print i[j]
break