Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Text;
- using System.Text.RegularExpressions;
- public class Problem_12_LittleJohn
- {
- public static void Main()
- {
- StringBuilder number = new StringBuilder();
- int smallArrows = 0;
- int middleArrows = 0;
- int largeArrows = 0;
- for (int i = 0; i < 4; i++)
- {
- string arrowRow = Console.ReadLine();
- string pattern = @"(>>>----->>)|(>>----->)|(>----->)";
- Regex rgx = new Regex(pattern);
- Match match = rgx.Match(arrowRow);
- while (match.Success)
- {
- string isMatch = match.Groups[1].Value;
- if (!string.IsNullOrEmpty(isMatch))
- {
- largeArrows++;
- }
- isMatch = match.Groups[2].Value;
- if (!string.IsNullOrEmpty(isMatch))
- {
- middleArrows++;
- }
- isMatch = match.Groups[3].Value;
- if (!string.IsNullOrEmpty(isMatch))
- {
- smallArrows++;
- }
- match = match.NextMatch();
- }
- }
- if (smallArrows == 0 && middleArrows != 0)
- {
- number.Append(middleArrows);
- number.Append(largeArrows);
- }
- else if (smallArrows != 0 && middleArrows != 0)
- {
- number.Append(smallArrows);
- number.Append(middleArrows);
- number.Append(largeArrows);
- }
- else if (smallArrows != 0)
- {
- number.Append(smallArrows);
- number.Append(middleArrows);
- number.Append(largeArrows);
- }
- else
- {
- number.Append(largeArrows);
- }
- string bin = Convert.ToString(int.Parse(number.ToString()), 2);
- char[] binArr = bin.ToCharArray();
- Array.Reverse(binArr);
- StringBuilder joinedBin = new StringBuilder(bin + new string(binArr));
- int result = Convert.ToInt32(joinedBin.ToString(), 2);
- Console.WriteLine(result);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment