Advertisement
fbinnzhivko

02.00 Game of Names

Apr 26th, 2016
206
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.51 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. class Program
  4. {
  5.     static void Main()
  6.     {
  7.         //Input & Variables
  8.         var n = int.Parse(Console.ReadLine());
  9.         string name = "";
  10.         int points = 0;
  11.         string winner = "";
  12.         int winnerPoints = -100000;
  13.  
  14.         //Create a list of the students & student points
  15.         List<string> students = new List<string>();
  16.         List<int> studentPoints = new List<int>();
  17.  
  18.         //Split the entries into the lists
  19.         for (int i = 0; i < n; i++)
  20.         {
  21.             students.Add(Console.ReadLine());
  22.             studentPoints.Add(int.Parse(Console.ReadLine()));
  23.         }
  24.         for (int i = 0; i < n; i++)
  25.         {
  26.             //Use Current Student's name            
  27.             name = students[i];
  28.             points = 0;
  29.             points = points + studentPoints[i];
  30.  
  31.             //Acquire Current Student's Points
  32.             foreach (char c in name)
  33.             {
  34.                 if ((int)c % 2 == 0)
  35.                 {
  36.                     points += (int)c;
  37.                 }
  38.                 else
  39.                 {
  40.                     points -= (int)c;
  41.                 }
  42.             }
  43.             //Check who has the highest number of points            
  44.             if (points > winnerPoints)
  45.             {
  46.                 winner = name;
  47.                 winnerPoints = points;
  48.             }
  49.         }
  50.         //Output
  51.         Console.WriteLine("The winner is {0} - {1} points", winner, winnerPoints);
  52.     }
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement