Alexander7337

ReGeXTaskLJ

Jun 16th, 2016
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.14 KB | None | 0 0
  1. using System;
  2. using System.Text;
  3. using System.Text.RegularExpressions;
  4.  
  5. public class Problem_12_LittleJohn
  6. {
  7.     public static void Main()
  8.     {
  9.         StringBuilder number = new StringBuilder();
  10.         int smallArrows = 0;
  11.         int middleArrows = 0;
  12.         int largeArrows = 0;
  13.         for (int i = 0; i < 4; i++)
  14.         {
  15.             string arrowRow = Console.ReadLine();
  16.             string pattern = @"(>>>----->>)|(>>----->)|(>----->)";
  17.             Regex rgx = new Regex(pattern);
  18.             Match match = rgx.Match(arrowRow);
  19.             while (match.Success)
  20.             {
  21.                 string isMatch = match.Groups[1].Value;
  22.                 if (!string.IsNullOrEmpty(isMatch))
  23.                 {
  24.                     largeArrows++;              
  25.                 }
  26.                 isMatch = match.Groups[2].Value;
  27.                 if (!string.IsNullOrEmpty(isMatch))
  28.                 {
  29.                     middleArrows++;
  30.                 }
  31.                 isMatch = match.Groups[3].Value;
  32.                 if (!string.IsNullOrEmpty(isMatch))
  33.                 {
  34.                     smallArrows++;
  35.                 }
  36.  
  37.                 match = match.NextMatch();
  38.             }
  39.         }
  40.  
  41.         if (smallArrows == 0 && middleArrows != 0)
  42.         {
  43.             number.Append(middleArrows);
  44.             number.Append(largeArrows);
  45.         }
  46.         else if (smallArrows != 0 && middleArrows != 0)
  47.         {
  48.             number.Append(smallArrows);
  49.             number.Append(middleArrows);
  50.             number.Append(largeArrows);
  51.         }
  52.         else if (smallArrows != 0)
  53.         {
  54.             number.Append(smallArrows);
  55.             number.Append(middleArrows);
  56.             number.Append(largeArrows);
  57.         }
  58.         else
  59.         {
  60.             number.Append(largeArrows);
  61.         }
  62.  
  63.         string bin = Convert.ToString(int.Parse(number.ToString()), 2);
  64.         char[] binArr = bin.ToCharArray();
  65.         Array.Reverse(binArr);
  66.         StringBuilder joinedBin = new StringBuilder(bin + new string(binArr));
  67.         int result = Convert.ToInt32(joinedBin.ToString(), 2);
  68.         Console.WriteLine(result);
  69.     }
  70. }
Advertisement
Add Comment
Please, Sign In to add comment