Advertisement
stanevplamen

02.09.02.01.DurankulakNumber

Jun 19th, 2013
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.58 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3.  
  4. class DurankulakNumbers
  5. {
  6.     static List<char> Reverse(string input)
  7.     {
  8.         List<char> revInput = new List<char>();
  9.  
  10.         for (int i = input.Length - 1; i >= 0; i--)
  11.         {
  12.             revInput.Add(input[i]);
  13.         }
  14.         return revInput;
  15.     }
  16.  
  17.     static long Convert(List<char> revInput, long numSystem)
  18.     {
  19.         long counterTwo = 1;
  20.         long counter = -1;
  21.         List<long> numbersList = new List<long>();
  22.         long temp = 0;
  23.         long numb = 0;
  24.         bool sign = false;
  25.         for (int i = 0; i < revInput.Count; i++)
  26.         {
  27.             if ((long)revInput[i] >= 97 && (long)revInput[i] <= 102)
  28.             {
  29.                 temp = temp + (26 * (revInput[i] - 96));
  30.                 counterTwo++;
  31.             }
  32.             if (sign == false)
  33.             {
  34.                 numb = numb + temp * (long)Math.Pow(numSystem, counter);
  35.                 sign = true;
  36.             }
  37.             if ((long)revInput[i] >= 65 && (long)revInput[i] <= 90)
  38.             {
  39.                 temp = ((long)revInput[i] - 65);
  40.                 counter++;
  41.                 sign = false;
  42.             }
  43.         }
  44.         if (sign == false)
  45.         {
  46.             numb = numb + temp * (long)Math.Pow(numSystem, counter);
  47.         }
  48.         return numb;
  49.     }
  50.  
  51.     static void Main()
  52.     {
  53.         string input = (Console.ReadLine());
  54.         long numSystem = 168;
  55.         List<char> revInput = Reverse(input);
  56.         long output = Convert(revInput, numSystem);
  57.         Console.WriteLine(output);
  58.     }
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement