Advertisement
gua543

Calculation Problem

Mar 8th, 2015
293
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.88 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.Numerics;
  7.  
  8. namespace ConsoleApplication3
  9. {
  10.     class Program
  11.     {
  12.         static string ReverseString(string result)
  13.         {
  14.             char[] reversedResult = result.ToCharArray();
  15.             Array.Reverse(reversedResult);
  16.             return new string(reversedResult);
  17.         }
  18. //Поради някаква причина ми изкарва резултата наобратно (вместо abc примерно, ми дава cba) та затова съществува горния метод
  19.         static void Main(string[] args)
  20.         {
  21.             string[] userInput = Console.ReadLine().Split(new char[] {' '}, StringSplitOptions.RemoveEmptyEntries);
  22.             for (int i = 0; i < userInput.Length; i++)
  23.             {
  24.                 string inputWord = userInput[i];
  25.                 BigInteger decResult = 0;
  26.                 for (int j = inputWord.Length - 1, power = 0; j >= 0; j--, power++)
  27.                 {
  28.                     BigInteger letter = inputWord[j] - 'a';
  29.                     decResult += letter * BigInteger.Pow(23, power);
  30.                 }
  31.                 BigInteger anotherDecResult = decResult;
  32.                 string result = string.Empty;
  33.                 string anotherResult = string.Empty;
  34.                 while (anotherDecResult > 0)
  35.                 {
  36.                     BigInteger anotherLetterAsNumber = anotherDecResult % 23;
  37.                     anotherDecResult /= 23;
  38.                     char anotherLetterAsLetter = (char)(anotherLetterAsNumber + 'a');
  39.                     result += anotherLetterAsLetter;
  40.                 }
  41.                 Console.Write(ReverseString(result) + " = ");
  42.                 Console.Write(decResult);
  43.                 Console.ReadLine();    
  44.             }
  45.         }
  46.     }
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement