borko9696

Untitled

Oct 8th, 2015
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.77 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text.RegularExpressions;
  4.  
  5. namespace _11.LittleJohn
  6. {
  7.     class LittleJohn
  8.     {
  9.         static void Main(string[] args)
  10.         {
  11.             const string large = ">>>----->>";
  12.             const string medium = ">>----->";
  13.             const string small = ">----->";
  14.             string input;
  15.             Dictionary<string, int> arrows = new Dictionary<string, int>()
  16.             {
  17.                 {large, 0},
  18.                 {medium, 0},
  19.                 {small, 0},
  20.             };
  21.  
  22.             Regex rgx = new Regex(@"(>>>----->>)|(>>----->)|(>----->)");
  23.  
  24.             for (int i = 0; i < 4; i++)
  25.             {
  26.                 input = " " + Console.ReadLine() + " ";
  27.                 Match match = rgx.Match(input);
  28.  
  29.                 while (match != Match.Empty)
  30.                 {
  31.                     switch (match.Value)
  32.                     {
  33.                         case large:
  34.                             arrows[large]++;
  35.                             break;
  36.                         case medium:
  37.                             arrows[medium]++;
  38.                             break;
  39.                         case small:
  40.                             arrows[small]++;
  41.                             break;
  42.                     }
  43.  
  44.                     match = match.NextMatch();
  45.                 }
  46.             }
  47.  
  48.             uint result = uint.Parse(String.Format("{0}{1}{2}", arrows[small], arrows[medium], arrows[large]));
  49.             string binary = Convert.ToString(result, 2);
  50.             char[] arr = binary.ToCharArray();
  51.             Array.Reverse(arr);
  52.             binary += new string(arr);
  53.             result = Convert.ToUInt32(binary, 2);
  54.  
  55.             Console.WriteLine(result);
  56.  
  57.         }
  58.     }
  59. }
Advertisement
Add Comment
Please, Sign In to add comment