Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.IO;
- using System.Linq;
- class Solution
- {
- static void Main(String[] args)
- {
- var n = int.Parse(Console.ReadLine());
- var input = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
- var mean = input.Sum() / (double)n;
- input = input.OrderBy(x => x).ToArray();
- var median = (input[n / 2] + input[(n / 2 - 1)]) / 2.0;
- var repeatInt = new Dictionary<int, int>();
- foreach (var num in input)
- {
- if (!repeatInt.ContainsKey(num))
- {
- repeatInt.Add(num, 0);
- }
- repeatInt[num]++;
- }
- repeatInt = repeatInt.OrderBy(x => x.Value).ThenBy(x => x.Key).ToDictionary(x =>x.Key, x => x.Value);
- var mode = 0;
- if (repeatInt.Values.Max() != 1)
- {
- mode = repeatInt.Values.Max();
- }
- else
- {
- mode = repeatInt.Keys.Min();
- }
- Console.WriteLine($"{mean:F1}");
- Console.WriteLine($"{median:F1}");
- Console.WriteLine($"{mode}");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment