Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- namespace Problem_11___Little_John
- {
- using System;
- using System.Text;
- using System.Text.RegularExpressions;
- using System.Numerics;
- internal class LittleJohn
- {
- private const string largeArrow = ">>>----->>";
- private const string mediumArrow = ">>----->";
- private const string smallArrow = ">----->";
- private static void Main(string[] args)
- {
- StringBuilder sb = new StringBuilder();
- for (int i = 0; i < 4; i++)
- {
- string line = Console.ReadLine();
- sb.Append(line);
- sb.Append(" ");
- }
- int countLarge = 0;
- int countMedium = 0;
- int countSmall = 0;
- string text = sb.ToString();
- string pattern = @"(>>>----->>)|(>>----->)|(>----->)";
- Regex rgx = new Regex(pattern);
- MatchCollection matches = rgx.Matches(text);
- foreach (Match match in matches)
- {
- if (match.Groups[1].Value == largeArrow)
- {
- countLarge++;
- }
- else if (match.Groups[2].Value == mediumArrow)
- {
- countMedium++;
- }
- else if (match.Groups[3].Value == smallArrow)
- {
- countSmall++;
- }
- }
- int number = countSmall * 100 + countMedium * 10 + countLarge;
- string binaryNum = Convert.ToString(number, 2);
- char[] reversed = binaryNum.ToCharArray();
- Array.Reverse(reversed);
- string reversedNum = new string(reversed);
- string stringApend = binaryNum + reversedNum;
- string result = Convert.ToUInt64(stringApend, 2).ToString();
- Console.WriteLine(result);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment