Advertisement
murkata86

Little John

Jun 13th, 2016
195
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.45 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3. using System.Text;
  4. using System.Text.RegularExpressions;
  5.  
  6. class LittleJohn
  7. {
  8.     static void Main()
  9.     {
  10.         string arrowTypePattern = @"\W{1,3}\-{5}\W{1,2}";
  11.  
  12.         string smallArrowPattern = @">{1}\-{5}\>{1}";
  13.         string mediumArrowPattern = @">{2}\-{5}\>{1}";
  14.         string largeArrowPattern = @">{3}\-{5}\>{2}";
  15.  
  16.         Regex typeRegex = new Regex(arrowTypePattern);
  17.         Regex smallRegex = new Regex(smallArrowPattern);
  18.         Regex mediumRegex = new Regex(mediumArrowPattern);
  19.         Regex largeRegex = new Regex(largeArrowPattern);
  20.  
  21.         int largeArrowsCount = 0;
  22.         int mediumArrowsCount = 0;
  23.         int smallArrowsCount = 0;
  24.  
  25.         for (int i = 0; i < 4; i++)
  26.         {
  27.             string input = Console.ReadLine();
  28.  
  29.             MatchCollection match = typeRegex.Matches(input);
  30.  
  31.             if (match.Count > 0)
  32.             {
  33.  
  34.                 foreach (var arrow in match)
  35.                 {
  36.                     Match largeArrowMatch = largeRegex.Match(arrow.ToString());
  37.  
  38.                     if (largeArrowMatch.Success)
  39.                     {
  40.                         largeArrowsCount++;
  41.                     }
  42.                     else
  43.                     {
  44.                         Match mediumArrowMatch = mediumRegex.Match(arrow.ToString());
  45.  
  46.                         if (mediumArrowMatch.Success)
  47.                         {
  48.                             mediumArrowsCount++;
  49.                         }
  50.                         else
  51.                         {
  52.                             Match smallArrowMatch = smallRegex.Match(arrow.ToString());
  53.  
  54.                             if (smallArrowMatch.Success)
  55.                             {
  56.                                 smallArrowsCount++;
  57.                             }
  58.                         }
  59.                     }
  60.                 }
  61.             }
  62.         }
  63.  
  64.         int theNumbderInDec = 100 * smallArrowsCount + 10 * mediumArrowsCount + largeArrowsCount;
  65.  
  66.         string theNumberInBinary = Convert.ToString(theNumbderInDec, 2);
  67.  
  68.         StringBuilder sb = new StringBuilder();
  69.  
  70.         for (int i = theNumberInBinary.Length - 1; i >= 0; i--)
  71.         {
  72.             sb.Append(theNumberInBinary[i]);
  73.         }
  74.        
  75.         string combinedNumber = theNumberInBinary + sb.ToString();
  76.  
  77.         int combinedNumberInDec = Convert.ToInt32(combinedNumber, 2);
  78.         Console.WriteLine(combinedNumberInDec);
  79.     }
  80. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement