Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace _1
- {
- class Program
- {
- static void Main(string[] args)
- {
- string[] catNumbersDict = new string[23];
- for (int i = 0; i < catNumbersDict.Length; i++)
- {
- catNumbersDict[i] = ((char)(97 + i)).ToString();
- }
- string[] numbers = Console.ReadLine()
- .Split(new char[] { ' ', ',' }, StringSplitOptions.RemoveEmptyEntries);
- var numbersIn23th = new List<List<int>>();
- // get the numbers in 23th system
- for (int j = 0; j < numbers.Length; j++)
- {
- string currentMewNum = numbers[j];
- // for every mew number
- var numIn23 = new List<int>();
- foreach (var digit in currentMewNum)
- {
- for (int k = 0; k < catNumbersDict.Length; k++)
- {
- if (digit.ToString() == catNumbersDict[k])
- {
- numIn23.Add(k);
- }
- }
- }
- numbersIn23th.Add(numIn23);
- }
- // Console.WriteLine(string.Join("!", numbersIn23th));
- var numbersInDecimal = new List<int>();
- int numberInDecimal = 0;
- for (int curNum = 0; curNum < numbersIn23th.Count; curNum++)
- {
- for (int currDigit = 0; currDigit < numbersIn23th[curNum].Count; currDigit++)
- {
- int pow = numbersIn23th[curNum].Count - currDigit - 1;
- int curentDigit = numbersIn23th[curNum][currDigit];
- numberInDecimal += curentDigit * (int)Math.Pow(23, pow);
- }
- numbersInDecimal.Add(numberInDecimal);
- numberInDecimal = 0;
- }
- //sum in decimal
- int sumDec = 0;
- for (int i = 0; i < numbersInDecimal.Count; i++)
- {
- sumDec += numbersInDecimal[i];
- }
- //convert the sum in 23th system
- string result = DecimalToAny(23, sumDec);
- Console.WriteLine("{0} = {1}", result, sumDec);
- }
- private static string DecimalToAny(int d, int decimalResult)
- {
- string result = string.Empty;
- if (decimalResult == 0) result = "0";
- while (decimalResult > 0)
- {
- int remainder = decimalResult % d;
- result += (char)((remainder + 97));
- decimalResult /= d;
- }
- var reverseResult = result.ToCharArray().Reverse();
- return string.Join("", reverseResult);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement