Advertisement
Guest User

Sum Cards

a guest
Oct 3rd, 2015
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.48 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Text.RegularExpressions;
  6. using System.Threading.Tasks;
  7.  
  8. namespace judge
  9. {
  10.     class judge
  11.     {
  12.         static void Main(string[] args)
  13.         {
  14.             List<string> cards = Console.ReadLine().Split(' ').Where(s => !string.IsNullOrWhiteSpace(s)).ToList();
  15.             int count = 0;
  16.             int prevValue = -1;
  17.             int sum = 0;
  18.             for (int i = 0; i < cards.Count; i++)
  19.             {
  20.                 int value = CardValue(cards[i]);
  21.                 if (value == prevValue)
  22.                 {
  23.                     count++;
  24.                 }
  25.                 else
  26.                 {
  27.                     count = 1;
  28.                 }
  29.                 sum = sum + value;
  30.                 if (count == 2)
  31.                 {
  32.                     sum = sum + 2 * value;
  33.                 }
  34.                 if (count > 2)
  35.                 {
  36.                     sum = sum + value;
  37.                 }
  38.                 prevValue = value;
  39.             }
  40.  
  41.             Console.WriteLine(sum);
  42.         }
  43.  
  44.         static int CardValue(string card)
  45.         {
  46.             if (card[0] == '2')
  47.             {
  48.                 return 2;
  49.             }
  50.             else if (card[0] == '3')
  51.             {
  52.                 return 3;
  53.             }
  54.             else if (card[0] == '4')
  55.             {
  56.                 return 4;
  57.             }
  58.             else if (card[0] == '5')
  59.             {
  60.                 return 5;
  61.             }
  62.             else if (card[0] == '6')
  63.             {
  64.                 return 6;
  65.             }
  66.             else if (card[0] == '7')
  67.             {
  68.                 return 7;
  69.             }
  70.             else if (card[0] == '8')
  71.             {
  72.                 return 8;
  73.             }
  74.             else if (card[0] == '9')
  75.             {
  76.                 return 9;
  77.             }
  78.             else if (card.Substring(0, 2) == "10")
  79.             {
  80.                 return 10;
  81.             }
  82.             else if (card[0] == 'J')
  83.             {
  84.                 return 12;
  85.             }
  86.             else if (card[0] == 'Q')
  87.             {
  88.                 return 13;
  89.             }
  90.             else if (card[0] == 'K')
  91.             {
  92.                 return 14;
  93.             }
  94.             else if (card[0] == 'A')
  95.             {
  96.                 return 15;
  97.             }
  98.             else
  99.             {
  100.                 return 0;
  101.             }
  102.         }
  103.     }
  104. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement