Advertisement
Guest User

Untitled

a guest
Oct 18th, 2017
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.71 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace T5_HandsOfCards
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             var powers = new Dictionary<string, int>()
  14.             {
  15.                 {"2",2},
  16.                 {"3",3},
  17.                 {"4",4},
  18.                 {"5",5},
  19.                 {"6",6},
  20.                 {"7",7},
  21.                 {"8",8},
  22.                 {"9",9},
  23.                 {"10",10},
  24.                 {"J",11},
  25.                 {"Q",12},
  26.                 {"K",13},
  27.                 {"A",14}
  28.             };
  29.  
  30.             var multipliers = new Dictionary<string, int>()
  31.             {
  32.                 {"S",4 },
  33.                 {"H",3 },
  34.                 {"D",2 },
  35.                 {"C",1 }
  36.             };
  37.  
  38.            
  39.             var playersNamesAndHands = new Dictionary<string, List<string>>();
  40.  
  41.             while (true)
  42.             {
  43.  
  44.                 string inputStr = Console.ReadLine();
  45.  
  46.                 if (inputStr != "JOKER")
  47.                 {
  48.  
  49.                     string name = inputStr.Substring(0, inputStr.IndexOf(':'));
  50.                     inputStr = inputStr.Substring(inputStr.IndexOf(':') + 1, inputStr.Length - (inputStr.IndexOf(':') + 1));
  51.                     string[] input = inputStr.Split(new[] { ",", " " }, StringSplitOptions.RemoveEmptyEntries);
  52.  
  53.                     if (!playersNamesAndHands.ContainsKey(name))
  54.                     {
  55.                         playersNamesAndHands[name] = new List<string>();
  56.                     }
  57.  
  58.                     for(int i = 0; i < input.Length; i++)
  59.                     {
  60.                         if (!playersNamesAndHands[name].Contains(input[i]))
  61.                         {
  62.                             playersNamesAndHands[name].Add(input[i]);
  63.                         }
  64.                     }
  65.  
  66.  
  67.                 }
  68.                 else
  69.                 {
  70.                     foreach (var playerCards in playersNamesAndHands)
  71.                     {
  72.  
  73.                        
  74.                         int sum = 0;
  75.                         for (int i = 0; i < playerCards.Value.Count; i++)
  76.                         {
  77.  
  78.                             string power = playerCards.Value[i].Substring(0, playerCards.Value[i].Length - 1);
  79.                             string multi = playerCards.Value[i].Substring(playerCards.Value[i].Length - 1,1);
  80.  
  81.                             sum += powers[power] * multipliers[multi];
  82.  
  83.                         }
  84.  
  85.                         Console.WriteLine("{0}: {1}", playerCards.Key, sum);
  86.  
  87.  
  88.  
  89.                     }
  90.  
  91.  
  92.  
  93.                 }
  94.             }
  95.  
  96.  
  97.  
  98.         }
  99.     }
  100. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement