Advertisement
duratsia

Untitled

Aug 29th, 2018
388
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.10 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 _02.Convert_from_Base_10_to_Base_N
  9. {
  10.     class Program
  11.     {
  12.         static void Main(string[] args)
  13.         {
  14.             string[] input = Console.ReadLine().Split().ToArray();
  15.  
  16.             int Base = int.Parse(input[0]);
  17.  
  18.             BigInteger result = 0;
  19.  
  20.             StringBuilder numSB = new StringBuilder(input[1]);
  21.  
  22.             int power = 0; // сложих int вместо double
  23.             int currentDigit = 0;
  24.             BigInteger currRes = 0;
  25.  
  26.             int len = numSB.Length;
  27.            
  28.  
  29.             for (int i = 0; i < len; i++)
  30.             {
  31.  
  32.                 currentDigit = int.Parse(numSB[numSB.Length - 1 - i].ToString());
  33.  
  34.                 //power = Math.Pow(Base, i); вместо i исползвам pow++
  35.                 currRes = currentDigit * BigInteger.Pow(Base, power);
  36.                 result += currRes;
  37.                 power++;
  38.             }
  39.             Console.WriteLine(result);
  40.  
  41.         }
  42.     }
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement