Advertisement
milislavski

Your code

May 31st, 2016
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.54 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Numerics;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7.  
  8. namespace De_code_cat
  9. {
  10.     class Program
  11.     {
  12.         static void Main(string[] args)
  13.         {
  14.             string[] input = Console.ReadLine().Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
  15.  
  16.             var allLeters = new List<char>();//нямаш нужда да подаваш от колко елемента да ти е листа
  17.  
  18.             //тук ти променям цикъла да върти до z
  19.             for (var i = 'a'; i <= 'z'; i++)
  20.             {
  21.                 allLeters.Add(i);
  22.             }
  23.  
  24.             BigInteger sumInDecimal = 0; //тук сменям вар с BigInteger
  25.  
  26.             //first loop for every encrypted word
  27.             for (int i = 0; i < input.Length; i++)
  28.             {
  29.  
  30.                 //second loop for every char in every word
  31.  
  32.                 var currentNumbers = new List<int>();
  33.                 for (int j = 0; j < input[i].Length; j++)
  34.                 {
  35.  
  36.                     var currentSymbol = input[i][j];
  37.                     currentNumbers.Add(allLeters.IndexOf(currentSymbol));
  38.                 }
  39.                 for (int k = 0; k < currentNumbers.Count; k++)
  40.                 {
  41.                     var currentPower = currentNumbers.Count - k - 1;
  42.                     sumInDecimal += currentNumbers[k] * (BigInteger)Math.Pow(21, currentPower);//mathpow връща double keep in mind                    
  43.                     //тук вместо (int)Math.Pow сменям на биг инт
  44.                 }
  45.                 BigInteger copyOfDecimalSystem = sumInDecimal;
  46.                 sumInDecimal = 0;
  47.                 StringBuilder result = new StringBuilder();
  48.  
  49.                 while (copyOfDecimalSystem > 0)
  50.                 {
  51.                     BigInteger currentNumber = copyOfDecimalSystem;
  52.                     currentNumber = copyOfDecimalSystem % 26;
  53.                     result.Insert(0, allLeters[(int)currentNumber]);
  54.                     //гърми ти на този ред тъй като copyOfDecimalSystem е винаги число до 26
  55.                     //а в allLeters преди да циклиш до z има само 21 елемента и индекса става -1
  56.                     copyOfDecimalSystem = copyOfDecimalSystem / 26;
  57.                 }
  58.  
  59.                 Console.Write("{0} ", result);
  60.  
  61.             }
  62.             Console.WriteLine();
  63.  
  64.  
  65.         }
  66.     }
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement