Advertisement
tanya_zheleva

Untitled

Feb 7th, 2017
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.66 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5.  
  6. namespace ExamPreparation
  7. {
  8.     public sealed class Card
  9.     {
  10.         public Card(string type, string power)
  11.         {
  12.             this.Type = type;
  13.             this.Power = power;
  14.         }
  15.  
  16.         public string Type { get; private set; }
  17.  
  18.         public string Power { get; private set; }
  19.  
  20.         public int Value
  21.         {
  22.             get
  23.             {
  24.                 int type = CalculateType();
  25.                 int power = CalculatePower();
  26.  
  27.                 return type * power;
  28.             }
  29.         }
  30.  
  31.         private int CalculatePower()
  32.         {
  33.             int power = 0;
  34.  
  35.             switch (this.Power)
  36.             {
  37.                 case "2":
  38.                 case "3":
  39.                 case "4":
  40.                 case "5":
  41.                 case "6":
  42.                 case "7":
  43.                 case "8":
  44.                 case "9":
  45.                 case "10":
  46.                     power = int.Parse(this.Power);
  47.                     break;
  48.  
  49.                 case "J":
  50.                     power = 11;
  51.                     break;
  52.  
  53.                 case "Q":
  54.                     power = 12;
  55.                     break;
  56.  
  57.                 case "K":
  58.                     power = 13;
  59.                     break;
  60.  
  61.                 case "A":
  62.                     power = 14;
  63.                     break;
  64.             }
  65.  
  66.             return power;
  67.         }
  68.  
  69.         private int CalculateType()
  70.         {
  71.             int type = 0;
  72.  
  73.             switch (this.Type)
  74.             {
  75.                 case "S":
  76.                     type = 4;
  77.                     break;
  78.  
  79.                 case "H":
  80.                     type = 3;
  81.                     break;
  82.  
  83.                 case "D":
  84.                     type = 2;
  85.                     break;
  86.  
  87.                 case "C":
  88.                     type = 1;
  89.                     break;
  90.             }
  91.  
  92.             return type;
  93.         }
  94.     }
  95.  
  96.     public sealed class Preparation
  97.     {
  98.         public static void Main()
  99.         {
  100.             string input = Console.ReadLine();
  101.             Dictionary<string, List<Card>> people = new Dictionary<string, List<Card>>();
  102.  
  103.             while (input != "JOKER")
  104.             {
  105.                 string[] tokens = input.Split(new[] { ':' }, StringSplitOptions.RemoveEmptyEntries);
  106.                 string[] cardTokens = tokens[1].Split(new[] { ' ', ',' }, StringSplitOptions.RemoveEmptyEntries);
  107.                 string player = tokens[0];
  108.  
  109.                 if (!people.ContainsKey(player))
  110.                 {
  111.                     people.Add(player, new List<Card>());
  112.                 }
  113.  
  114.                 for (int i = 0; i < cardTokens.Length; i++)
  115.                 {
  116.                     string currentCard = cardTokens[i];
  117.                     string type = currentCard[currentCard.Length - 1].ToString();
  118.                     StringBuilder power = new StringBuilder();
  119.                     power.Append(currentCard[0]);
  120.  
  121.                     if (currentCard.Length > 2)
  122.                     {
  123.                         power.Append(currentCard[1]);
  124.                     }
  125.  
  126.                     Card card = new Card(type, power.ToString());
  127.  
  128.                     if (!people[player].Any(c => c.Power == card.Power && c.Type == card.Type))
  129.                     {
  130.                         people[player].Add(card);
  131.                     }
  132.                 }
  133.  
  134.                 input = Console.ReadLine();
  135.             }
  136.  
  137.             foreach (var player in people)
  138.             {
  139.                 Console.WriteLine($"{player.Key}: {player.Value.Sum(c => c.Value)}");
  140.             }
  141.         }
  142.     }
  143. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement