borko9696

Untitled

Oct 9th, 2015
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.91 KB | None | 0 0
  1. namespace Problem_11___Little_John
  2. {
  3.     using System;
  4.     using System.Text;
  5.     using System.Text.RegularExpressions;
  6.     using System.Numerics;
  7.  
  8.     internal class LittleJohn
  9.     {
  10.         private const string largeArrow = ">>>----->>";
  11.  
  12.         private const string mediumArrow = ">>----->";
  13.  
  14.         private const string smallArrow = ">----->";
  15.  
  16.         private static void Main(string[] args)
  17.         {
  18.             StringBuilder sb = new StringBuilder();
  19.  
  20.             for (int i = 0; i < 4; i++)
  21.             {
  22.                 string line = Console.ReadLine();
  23.                 sb.Append(line);
  24.                 sb.Append(" ");
  25.             }
  26.             int countLarge = 0;
  27.             int countMedium = 0;
  28.             int countSmall = 0;
  29.  
  30.             string text = sb.ToString();
  31.             string pattern = @"(>>>----->>)|(>>----->)|(>----->)";
  32.             Regex rgx = new Regex(pattern);
  33.             MatchCollection matches = rgx.Matches(text);
  34.             foreach (Match match in matches)
  35.             {
  36.                 if (match.Groups[1].Value == largeArrow)
  37.                 {
  38.                     countLarge++;
  39.                 }
  40.                 else if (match.Groups[2].Value == mediumArrow)
  41.                 {
  42.                     countMedium++;
  43.                 }
  44.                 else if (match.Groups[3].Value == smallArrow)
  45.                 {
  46.                     countSmall++;
  47.                 }
  48.             }
  49.             int number = countSmall * 100 + countMedium * 10 + countLarge;
  50.             string binaryNum = Convert.ToString(number, 2);
  51.             char[] reversed = binaryNum.ToCharArray();
  52.             Array.Reverse(reversed);
  53.             string reversedNum = new string(reversed);
  54.             string stringApend = binaryNum + reversedNum;
  55.            
  56.             string result = Convert.ToUInt64(stringApend, 2).ToString();
  57.             Console.WriteLine(result);
  58.         }
  59.     }
  60. }
Advertisement
Add Comment
Please, Sign In to add comment