Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace 05. Multiply Big Number
- {
- class Program
- {
- static void Main(string[] args)
- {
- string bigNumber = Console.ReadLine();
- int singleDigit = int.Parse(Console.ReadLine());
- string result = string.Empty;
- int number = 0;
- int temp = 0;
- int firstDigit = 0;
- int lastDigit = 0;
- int naum = 0;
- if (singleDigit == 0)
- {
- Console.WriteLine(0);
- return;
- }
- for (int i = bigNumber.Length - 1; i >= 0; i--)
- {
- number = int.Parse(bigNumber[i].ToString());
- temp = number * singleDigit;
- lastDigit = temp % 10;
- if (temp >= 10)
- {
- firstDigit = temp / 10;
- }
- else
- {
- firstDigit = 0;
- }
- if (i == bigNumber.Length - 1)
- {
- result += lastDigit;
- }
- else
- {
- int tempResult = naum + lastDigit;
- if (tempResult >= 10)
- {
- lastDigit = tempResult % 10;
- result += lastDigit;
- firstDigit += tempResult / 10;
- }
- else
- {
- result += tempResult;
- }
- }
- naum = firstDigit;
- }
- if (firstDigit != 0)
- {
- result += naum;
- }
- string finalString = Reverse(result);
- int lenght = finalString.Length;
- for (int i = 0; i < lenght; i++)
- {
- char ch = finalString[0];
- if(ch == '0')
- {
- finalString =finalString.Remove(0, 1);
- }
- else
- {
- break;
- }
- }
- Console.WriteLine(finalString);
- }
- public static string Reverse(string s)
- {
- char[] charArray = s.ToCharArray();
- Array.Reverse(charArray);
- return new string(charArray);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement