Advertisement
simonradev

LittleJohn

May 13th, 2017
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.88 KB | None | 0 0
  1. namespace LittleJohn
  2. {
  3.     using System;
  4.     using System.Collections.Generic;
  5.     using System.Text;
  6.  
  7.     public class Startup
  8.     {
  9.         public static void Main()
  10.         {
  11.             string[] arrowTypes = new string[]
  12.             {
  13.                 ">>>----->>",
  14.                 ">>----->",
  15.                 ">----->",
  16.             };
  17.  
  18.             int inputLines = 4;
  19.             for (int currInputLine = 0; currInputLine < inputLines; currInputLine++)
  20.             {
  21.                 string inputLine = Console.ReadLine();
  22.  
  23.                 for (int currArrow = 0; currArrow < arrowTypes.Length; currArrow++)
  24.                 {
  25.                     string arrow = arrowTypes[currArrow];
  26.  
  27.                     int countOfCurrArrowType = 0;
  28.  
  29.                     int indexOfArrow = inputLine.IndexOf(arrow);
  30.                     while (indexOfArrow != -1)
  31.                     {
  32.                         countOfCurrArrowType++;
  33.                        
  34.                         indexOfArrow = inputLine.IndexOf(arrow, indexOfArrow + 1);
  35.                     }
  36.  
  37.                     inputLine = inputLine.Replace(arrow, "REPLACED");
  38.  
  39.                     ArrowCounter.AddArrows(currArrow, countOfCurrArrowType);
  40.                 }
  41.             }
  42.  
  43.             string specialBinaryNumber = NumberConverter.ConvertToSpecialBinary(ArrowCounter.SpecialNumber);
  44.  
  45.             Console.WriteLine(NumberConverter.ConvertToInt64FromSpecialBinary(specialBinaryNumber));
  46.         }
  47.     }
  48.  
  49.     public static class NumberConverter
  50.     {
  51.         public static string ConvertToSpecialBinary(int number)
  52.         {
  53.             StringBuilder result = new StringBuilder(Convert.ToString(number, 2));
  54.  
  55.             for (int currSymbol = result.Length - 1; currSymbol >= 0; currSymbol--)
  56.             {
  57.                 result.Append(result[currSymbol]);
  58.             }
  59.  
  60.             return result.ToString();
  61.         }
  62.  
  63.         public static long ConvertToInt64FromSpecialBinary(string specialBinary)
  64.         {
  65.             return Convert.ToInt64(specialBinary, 2);
  66.         }
  67.     }
  68.  
  69.     public static class ArrowCounter
  70.     {
  71.         private static Dictionary<ArrowType, int> arrowsCount = new Dictionary<ArrowType, int>
  72.         {
  73.             [ArrowType.Large] = 0,
  74.             [ArrowType.Medium] = 0,
  75.             [ArrowType.Small] = 0
  76.         };
  77.  
  78.         public static int SpecialNumber
  79.         {
  80.             get
  81.             {
  82.                 return arrowsCount[ArrowType.Small] * 100 +
  83.                        arrowsCount[ArrowType.Medium] * 10 +
  84.                        arrowsCount[ArrowType.Large];
  85.             }
  86.         }
  87.  
  88.         public static void AddArrows(int indexOfArrowType, int countOfArrowType)
  89.         {
  90.             arrowsCount[(ArrowType)indexOfArrowType] += countOfArrowType;
  91.         }
  92.     }
  93.  
  94.     public enum ArrowType
  95.     {
  96.         Large,
  97.         Medium,
  98.         Small
  99.     }
  100. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement