Advertisement
EmoRz

05. Hands of Cards

Jun 7th, 2018
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 4.90 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text.RegularExpressions;
  5.  
  6. namespace Temp
  7. {
  8.     class Program
  9.     {
  10.         static void Main(string[] args)
  11.         {
  12.             var inputData = Console.ReadLine();
  13.             List<string> data = new List<string>();
  14.             Dictionary<string, long> players = new Dictionary<string, long>();
  15.             Dictionary<string, List<string>> playersCards = new Dictionary<string, List<string>>();
  16.  
  17.             //.Split(new char[] { ',',' ',':'}, StringSplitOptions.RemoveEmptyEntries).ToList()
  18.             //
  19.             while (inputData != "JOKER")
  20.             {
  21.                 var dist = inputData.Split(new char[] { ',',' ',':' }, StringSplitOptions.RemoveEmptyEntries).Skip(1).ToList();
  22.                 var name = inputData.Split(new char[] { ':'}, StringSplitOptions.RemoveEmptyEntries).ToList();
  23.  
  24.                 if (!playersCards.ContainsKey(name[0]))
  25.                 {
  26.                     playersCards.Add(name[0], dist);
  27.                 }
  28.                 if (playersCards.ContainsKey(name[0]))
  29.                 {
  30.                     playersCards[name[0]].InsertRange(0, dist);
  31.                     playersCards[name[0]].Distinct();                  
  32.                 }
  33.  
  34.                 inputData = Console.ReadLine();
  35.             }
  36.             long type = 0;
  37.             long power = 0;
  38.             long sum = 0;
  39.            
  40.             foreach (var item in playersCards)
  41.             {
  42.                 foreach (var i in item.Value.Distinct())
  43.                 {
  44.                     var tempA = i;
  45.                     var first = "";
  46.                     for (int j = 0; j < i.Length-1; j++)
  47.                     {
  48.                         first += i[j];
  49.                     }
  50.                     var last = Convert.ToString(i[i.Length-1]);
  51.  
  52.                     if (last == "S" || last == "H" || last == "D" || last == "C")
  53.                     {
  54.                         if (last == "S")
  55.                         {
  56.                             type = 4;
  57.                         }
  58.                         if (last == "H")
  59.                         {
  60.                             type = 3;
  61.                         }
  62.                         if (last == "D")
  63.                         {
  64.                             type = 2;
  65.                         }
  66.                         if (last == "C")
  67.                         {
  68.                             type = 1;
  69.                         }
  70.                     }
  71.                     if (first =="2" ||first =="3"||first =="4"||first =="5"||first=="6"||first=="7"||first == "8"||first=="9"||first=="10"||
  72.                         first == "J"||first =="Q"||first == "K"||first=="A")
  73.                     {
  74.                         if (first=="2")
  75.                         {
  76.                             power = 2;
  77.                         }
  78.                         if (first == "3")
  79.                         {
  80.                             power = 3;
  81.                         }
  82.                         if (first == "4")
  83.                         {
  84.                             power = 4;
  85.                         }
  86.                         if (first == "5")
  87.                         {
  88.                             power = 5;
  89.                         }
  90.                         if (first == "6")
  91.                         {
  92.                             power = 6;
  93.                         }
  94.                         if (first == "7")
  95.                         {
  96.                             power = 7;
  97.                         }
  98.                         if (first == "8")
  99.                         {
  100.                             power = 8;
  101.                         }
  102.                         if (first == "9")
  103.                         {
  104.                             power = 9;
  105.                         }
  106.                         if (first == "10")
  107.                         {
  108.                             power = 10;
  109.                         }
  110.                         if (first == "J")
  111.                         {
  112.                             power = 11;
  113.                         }
  114.                         if (first == "Q")
  115.                         {
  116.                             power = 12;
  117.                         }
  118.                         if (first == "K")
  119.                         {
  120.                             power = 13;
  121.                         }
  122.                         if (first == "A")
  123.                         {
  124.                             power = 14;
  125.                         }
  126.  
  127.                     }
  128.                     sum += (type*power);
  129.                 }
  130.  
  131.                 if (!players.ContainsKey(item.Key))
  132.                 {
  133.                     players.Add(item.Key, sum);
  134.                 }
  135.  
  136.                 sum = 0;
  137.             }
  138.             foreach (var cardPlayers in players)
  139.             {
  140.                 Console.WriteLine($"{cardPlayers.Key}: {cardPlayers.Value}");
  141.             }
  142.         }
  143.     }
  144. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement