amphibia89

02. Hogwarts Sorting

Apr 18th, 2016
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.23 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4.  
  5. class Program
  6. {
  7.  
  8.     static void Main(string[] args)
  9.     {
  10. #if DEBUG
  11.         Console.SetIn(new StreamReader("../../../input.txt"));
  12. #endif
  13.         string[] houses = { "Gryffindor", "Slytherin", "Ravenclaw", "Hufflepuff" };
  14.         int[] studentCounts = { 0, 0, 0, 0 };
  15.  
  16.         int studentCount = int.Parse(Console.ReadLine());
  17.  
  18.         for (int count = 0; count < studentCount; count++)
  19.         {
  20.             string studentName = Console.ReadLine();
  21.             int asciiSum = GetAsciiSum(studentName);
  22.             int remainder = asciiSum % 4;
  23.  
  24.             string[] studentNames = studentName.Split();
  25.             Console.WriteLine($"{houses[remainder]} {asciiSum}{studentNames[0][0]}{studentNames[1][0]}");
  26.  
  27.             studentCounts[remainder]++;
  28.         }
  29.  
  30.         Console.WriteLine();
  31.         for (int index = 0; index < 4; index++)
  32.             Console.WriteLine($"{houses[index]}: {studentCounts[index]}");
  33.     }
  34.  
  35.     private static int GetAsciiSum(string studentName)
  36.     {
  37.         int sum = 0;
  38.  
  39.         foreach (var character in studentName)
  40.             if (character != ' ')
  41.                 sum += character;
  42.  
  43.         return sum;
  44.     }
  45. }
Advertisement
Add Comment
Please, Sign In to add comment