You are viewing a single comment's thread. Return to all comments →
using System; using System.Collections.Generic; using System.IO; using System.Linq; class Solution { static void Main(string[] args) { int n = Convert.ToInt32(Console.ReadLine()); string param = Console.ReadLine(); List<string> splitted = param.TrimEnd().Split().ToList(); List<int> list = new List<int>(n); for (int i = 0; i < n; i++) { list.Add(Convert.ToInt32(splitted[i])); } list.Sort(); double mean = list.Average(a => a); double stddev = StandardDeviation(list, n, mean); Console.WriteLine(mean); Console.WriteLine(Median(list, n)); Console.WriteLine(Mode(list, n)); Console.WriteLine(Math.Round(stddev,1)); double lowerbound = Math.Round(LowerBoundConfidence(mean, stddev, n), 1); double upperbound = Math.Round(UpperBoundConfidence(mean, stddev, n), 1); Console.WriteLine(String.Format("{0:0.0}",lowerbound) +" "+ String.Format("{0:0.0}",upperbound)); } static double Median(List<int> list, int n) { if (n % 2 == 0) { var mid1 = n / 2; var mid2 = (n - 1) / 2; return Convert.ToDouble((list[mid1] + list[mid2])) / 2; } return list[(n + 1) / 2]; } static int Mode(List<int> list, int n) { return list .GroupBy(i => i) .OrderByDescending(g => g.Count()) .First().Key; } static double StandardDeviation(List<int> list,int n, double Mean) { double sum = 0; foreach (int i in list) { sum += Math.Pow(Convert.ToDouble(i)-Mean,2); } return Math.Pow(sum / n, 0.5); } static double UpperBoundConfidence(double mean,double standardDeviation,int n) { return mean+1.96 *(standardDeviation/ Math.Pow(n,0.5)); } static double LowerBoundConfidence(double mean, double standardDeviation, int n) { return mean - 1.96 * (standardDeviation / Math.Pow(n, 0.5)); } }
Seems like cookies are disabled on this browser, please enable them to open this website
Basic Statistics Warmup
You are viewing a single comment's thread. Return to all comments →