Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace ConsoleTesting2
- {
- class ConsoleTesting2
- {
- static void Main()
- {
- Console.Write("Enter array length: ");
- int n = int.Parse(Console.ReadLine());
- var ints = new int[n];
- for (int i = 0; i < n; i++)
- {
- Console.Write("Index \"{0}\": ", i);
- ints[i] = int.Parse(Console.ReadLine());
- }
- //Array.Sort(ints);
- var uniqueNums = ints.Distinct().ToList();
- var counts = new List<int>();
- for (int i = 0; i < uniqueNums.Count; i++)
- {
- int count = 0;
- for (int j = 0; j < n; j++)
- {
- if (ints[j] == uniqueNums[i])
- {
- count++;
- }
- }
- counts.Add(count);
- }
- Console.WriteLine("\nUnique nums and their occurences: ");
- for (int i = 0; i < uniqueNums.Count; i++)
- {
- Console.WriteLine("{0} ({1})", uniqueNums[i], counts[i]);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment