Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- namespace _03.SoftUniNumerals
- {
- using System;
- using System.Collections.Generic;
- using System.Text;
- using System.Numerics;
- public class SoftUniNumerals
- {
- public static void Main(string[] args)
- {
- string input = Console.ReadLine();
- string zero = "aa";
- string one = "aba";
- string two = "bcc";
- string three = "cc";
- string four = "cdc";
- int totalDigits = 0;
- List<int> digits = new List<int>();
- while (input.Length > 0)
- {
- if (input.StartsWith(zero))
- {
- input = input.Substring(zero.Length, input.Length - zero.Length);
- digits.Add(0);
- totalDigits++;
- }
- else if (input.StartsWith(one))
- {
- input = input.Substring(one.Length, input.Length - one.Length);
- digits.Add(1);
- totalDigits++;
- }
- else if (input.StartsWith(two))
- {
- input = input.Substring(two.Length, input.Length - two.Length);
- digits.Add(2);
- totalDigits++;
- }
- else if (input.StartsWith(three))
- {
- input = input.Substring(three.Length, input.Length - three.Length);
- digits.Add(3);
- totalDigits++;
- }
- else if (input.StartsWith(four))
- {
- input = input.Substring(four.Length, input.Length - four.Length);
- digits.Add(4);
- totalDigits++;
- }
- }
- BigInteger number = 0;
- StringBuilder numberAsString = new StringBuilder();
- for (int i = 0; i < digits.Count; i++)
- {
- numberAsString.Append(digits[i]);
- }
- BigInteger numberInDec = 0;
- int digitPos = digits.Count - 1;
- for (int n = 0; n < totalDigits; n++)
- {
- numberInDec += (BigInteger)digits[n] * Power(5,digitPos);
- digitPos--;
- }
- Console.WriteLine(numberInDec);
- }
- private static BigInteger Power(int fund, int pos)
- {
- BigInteger result = 1;
- for (int i = 0; i < pos; i++)
- {
- result *= fund;
- }
- return result;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement