Advertisement
Guest User

SoftUniNumerals

a guest
Feb 28th, 2016
166
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.70 KB | None | 0 0
  1. using System.Text.RegularExpressions;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. using System.Numerics;
  8.  
  9. namespace _3.SoftuniNumerals
  10. {
  11.     public class SoftuniNumerals
  12.     {
  13.         public static void Main()
  14.         {
  15.             var regex = new Regex("(aa)|(aba)|(bcc)|(cc)|(cdc)");
  16.             var numInBaseFive = new StringBuilder();
  17.             string numeralString = Console.ReadLine();
  18.             var matches = regex.Matches(numeralString);
  19.             foreach (Match match in matches)
  20.             {
  21.                 string digit = match.ToString();
  22.                 switch (digit)
  23.                 {
  24.                     case "aa":
  25.                         numInBaseFive.Append(0);
  26.                         break;
  27.                     case "aba":
  28.                         numInBaseFive.Append(1);
  29.                         break;
  30.                     case "bcc":
  31.                         numInBaseFive.Append(2);
  32.                         break;
  33.                     case "cc":
  34.                         numInBaseFive.Append(3);
  35.                         break;
  36.                     case "cdc":
  37.                         numInBaseFive.Append(4);
  38.                         break;
  39.                 }
  40.             }
  41.  
  42.             var numAsString = numInBaseFive.ToString();
  43.             BigInteger multiplier = 1;
  44.             BigInteger outputNum = 0;
  45.             for (int i = numAsString.Length - 1; i >= 0; i--, multiplier *=5)
  46.             {
  47.                 int digit = int.Parse(numAsString[i].ToString());
  48.                 outputNum += digit * multiplier;
  49.             }
  50.  
  51.             Console.WriteLine(outputNum);
  52.         }
  53.  
  54.     }
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement