home

C#

using System;
using System.Collections;

// blame: shardy@@differentchairs.com

namespace OddFinder
{
	class MainClass
	{
		public static object findOddCount(int [] val)
		{
			Hashtable bucket = new Hashtable();//prefer Generics, if supported
			for (int i=0; i<val.Length; i++)
			{
				int k = val[i];
				bucket[ k ] = bucket.ContainsKey(k) ? 1 + (int)bucket[k] : 1;
			}
			foreach (int vkey in bucket.Keys)
			{
				int v = (int)(bucket[vkey]);
				if (1==(v % 2))
				{
					return (object)vkey;
				}
			}
			return null;
		}

		[STAThread]
		static void Main(string[] args)
		{
			int[] a1= {1,1,2,2,3,3,4,4,5,5,6,7,7,7,7};
			int[] a2= {10,10,7,7,6,6, 2,2,3,3,4,4,5,5,6,7,7,7,7,10,10};
			int[] a3= {6,6,10,10,7,7,6,6, 2,2,3,3,4,4,5,5,6,7,7,7,7,10,10};
			int[] a4= {10,10,7,7, 2,2,3,3,4,4,5,5,7,7,7,7,10,10,6};
			int[] a5= {6,6};
			int[] a6= {1};

			System.Console.WriteLine("odd value in a1 is " + findOddCount(a1));
			System.Console.WriteLine("odd value in a2 is " + findOddCount(a2));
			System.Console.WriteLine("odd value in a3 is " + findOddCount(a3));
			System.Console.WriteLine("odd value in a4 is " + findOddCount(a4));
			System.Console.WriteLine("odd value in a5 is " + findOddCount(a5));
			System.Console.WriteLine("odd value in a6 is " + findOddCount(a6));
		}
	}
}