Advertisement
dimipan80

Little John

May 25th, 2015
273
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.51 KB | None | 0 0
  1. /* You are given 4 input strings (hay). Those strings may or may not contain arrows. The arrows can be of different type as follows: ">----->" – a small arrow; ">>----->" – a medium arrow; ">>>----->>" – a large arrow. Note that the body of each arrow will always be 5 dashes long. The difference between the arrows is in their tip and tail. The given 3 types are the only ones you should count, the rest should be ignored (Robin Hood does not like them). You should start searching the hays from the largest arrow type down to the smallest arrow type.After you find the count of each arrow type you should concatenate them into one number in order: small, medium, large arrow (even if the arrow count is 0). Then you convert the number in binary representation, reverse it and concatenate it again with the initial binary representation of the number. You convert the final binary number again back to decimal. The data will be received from 4 input lines containing strings. */
  2.  
  3. namespace _Little_John
  4. {
  5.     using System;
  6.     using System.Text;
  7.     using System.Text.RegularExpressions;
  8.  
  9.     class LittleJohn
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             const string pattern = @"(\>{3}\-{5}\>{2})|(\>{2}\-{5}\>)|(\>\-{5}\>)";
  14.             int small = 0;
  15.             int medium = 0;
  16.             int large = 0;
  17.             for (int i = 0; i < 4; i++)
  18.             {
  19.                 string arrow = Console.ReadLine();
  20.                 MatchCollection matches = Regex.Matches(arrow, pattern);
  21.                 foreach (Match match in matches)
  22.                 {
  23.                     if (!string.IsNullOrEmpty(match.Groups[1].Value))
  24.                     {
  25.                         large++;
  26.                     }
  27.                     else if (!string.IsNullOrEmpty(match.Groups[2].Value))
  28.                     {
  29.                         medium++;
  30.                     }
  31.                     else
  32.                     {
  33.                         small++;
  34.                     }
  35.                 }
  36.             }
  37.  
  38.             StringBuilder sb = new StringBuilder();
  39.             sb.Append(small).Append(medium).Append(large);
  40.             string binaryArrows = Convert.ToString(int.Parse(sb.ToString()), 2);
  41.             sb.Clear();
  42.             sb.Append(binaryArrows);
  43.             for (int i = binaryArrows.Length - 1; i >= 0; i--)
  44.             {
  45.                 sb.Append(binaryArrows[i]);
  46.             }
  47.  
  48.             int result = Convert.ToInt32(sb.ToString(), 2);
  49.             Console.WriteLine(result);
  50.         }
  51.     }
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement