Advertisement
Guest User

Exam Results

a guest
Apr 14th, 2015
307
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.58 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. class Week2ExamResultsCalculator
  6. {
  7.     static void Main()
  8.     {
  9.         // input
  10.         int A = int.Parse(Console.ReadLine());
  11.         int B = int.Parse(Console.ReadLine()); // not necessary
  12.  
  13.         // declarations
  14.         Dictionary<string, int> studentResults = new Dictionary<string, int>();
  15.  
  16.         // formating
  17.         string delimiter1 = new string('-', 23);
  18.         string delimiter2 = new string('-', 16);
  19.         int totalLength1 = 23;
  20.         int totalLength2 = 16;
  21.         string stringToCenter1 = "Course Results";
  22.         string centeredString1 =
  23.      stringToCenter1.PadLeft(((totalLength1 - stringToCenter1.Length) / 2)
  24.                             + stringToCenter1.Length)
  25.                    .PadRight(totalLength1);
  26.         string stringToCenter2 = "Students Results";
  27.         string centeredString2 =
  28.              stringToCenter2.PadLeft(((totalLength2 - stringToCenter2.Length) / 2)
  29.                                     + stringToCenter2.Length)
  30.                            .PadRight(totalLength2);
  31.  
  32.         // more input
  33.         for (int i = 0; i < A; i++)
  34.         {
  35.             string[] input = Console.ReadLine().Split(' ');
  36.             string name = input[0];
  37.             int[] pointsSubset = input.Skip(1).Take(input.Length - 1).Select(int.Parse).ToArray();
  38.             //Console.WriteLine(string.Join(" ", pointsSubset));
  39.             int studentTotal = pointsSubset.Sum();
  40.  
  41.             studentResults.Add(name, studentTotal);
  42.         }
  43.  
  44.         // formated print
  45.         Console.WriteLine();
  46.         Console.WriteLine(" {0} ", delimiter1);
  47.         Console.WriteLine("|{0}|", centeredString1);
  48.         Console.WriteLine(" {0} ", delimiter1);
  49.         Console.WriteLine("|{0, -15}|{1, -7:F2}|", "Average points", studentResults.Values.Average());
  50.         Console.WriteLine(" {0} ", delimiter1);
  51.         Console.WriteLine("|{0, -15}|{1, -7}|", "Max points", studentResults.Values.Max());
  52.         Console.WriteLine(" {0} ", delimiter1);
  53.         Console.WriteLine("|{0, -15}|{1, -7}|", "Mix points", studentResults.Values.Min());
  54.         Console.WriteLine(" {0} ", delimiter1);
  55.         Console.WriteLine();
  56.  
  57.         Console.WriteLine(" {0} ", delimiter2);
  58.         Console.WriteLine("|{0}|", centeredString2);
  59.         Console.WriteLine(" {0} ", delimiter2);
  60.         foreach (KeyValuePair<string, int> pair in studentResults)
  61.         {
  62.             Console.WriteLine("|{0, -10}|{1, -5}|", pair.Key, pair.Value);
  63.             Console.WriteLine(" {0} ", delimiter2);
  64.         }
  65.  
  66.     }
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement