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.Numerics;
- using System.Text;
- using System.Threading.Tasks;
- namespace De_code_cat
- {
- class Program
- {
- static void Main(string[] args)
- {
- string[] input = Console.ReadLine().Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
- var allLeters = new List<char>();//нямаш нужда да подаваш от колко елемента да ти е листа
- //тук ти променям цикъла да върти до z
- for (var i = 'a'; i <= 'z'; i++)
- {
- allLeters.Add(i);
- }
- BigInteger sumInDecimal = 0; //тук сменям вар с BigInteger
- //first loop for every encrypted word
- for (int i = 0; i < input.Length; i++)
- {
- //second loop for every char in every word
- var currentNumbers = new List<int>();
- for (int j = 0; j < input[i].Length; j++)
- {
- var currentSymbol = input[i][j];
- currentNumbers.Add(allLeters.IndexOf(currentSymbol));
- }
- for (int k = 0; k < currentNumbers.Count; k++)
- {
- var currentPower = currentNumbers.Count - k - 1;
- sumInDecimal += currentNumbers[k] * (BigInteger)Math.Pow(21, currentPower);//mathpow връща double keep in mind
- //тук вместо (int)Math.Pow сменям на биг инт
- }
- BigInteger copyOfDecimalSystem = sumInDecimal;
- sumInDecimal = 0;
- StringBuilder result = new StringBuilder();
- while (copyOfDecimalSystem > 0)
- {
- BigInteger currentNumber = copyOfDecimalSystem;
- currentNumber = copyOfDecimalSystem % 26;
- result.Insert(0, allLeters[(int)currentNumber]);
- //гърми ти на този ред тъй като copyOfDecimalSystem е винаги число до 26
- //а в allLeters преди да циклиш до z има само 21 елемента и индекса става -1
- copyOfDecimalSystem = copyOfDecimalSystem / 26;
- }
- Console.Write("{0} ", result);
- }
- Console.WriteLine();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement