tanya_zheleva

2

Feb 18th, 2017
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.86 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3. using System.Collections.Generic;
  4. using System.Numerics;
  5.  
  6. namespace ExamPreparation
  7. {
  8.     public sealed class Preparation
  9.     {
  10.         public static void Main()
  11.         {
  12.             string[] tokens = Console.ReadLine().Split();
  13.  
  14.             int baseN = int.Parse(tokens[0]);
  15.             string number = tokens[1];
  16.             string digits = "0123456789ABCDEF";
  17.             int power = number.Length - 1;
  18.             BigInteger sum = 0;
  19.  
  20.             for (int i = 0; i < number.Length; i++)
  21.             {
  22.                 char currentDigit = number[i];
  23.                 int index = digits.IndexOf(currentDigit);
  24.                 BigInteger raisedPower = BigInteger.Pow(baseN, power);
  25.                 sum += index * raisedPower;
  26.  
  27.                 power--;
  28.             }
  29.  
  30.             Console.WriteLine(sum);
  31.         }
  32.     }
  33. }
Add Comment
Please, Sign In to add comment