Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 10.Multiply Big Number
- You are given two lines – the first one can be a really big number (0 to 10Pow50). The second one will be a single digit number (0 to 9). You must display the product of these numbers.
- Note: do not use the BigInteger class.
- Examples
- Input Output
- 23 46
- 2
- 9999 89991
- 9
- 923847238931983192462832102 3695388955727932769851328408
- 4
- using System;
- using System.Collections.Generic;
- public class Program
- {
- public static void Main()
- {
- var bigInteger = Console.ReadLine().TrimStart(new char[] {'0'}).ToCharArray();//Ако е 0000005005 ще стане '5''0''0''5'!
- var singleDigit = int.Parse(Console.ReadLine());
- if (singleDigit == 0)
- {
- Console.WriteLine(0);
- return;
- }
- var result = new List<char>(); //Вместо char,може да е string.
- var multiplyByOneDigit = ""; //Вместо "" ще е 0.
- var onePlusMind = 0;
- for (int i = bigInteger.Length - 1; i >= 0; i--)
- {
- multiplyByOneDigit = (singleDigit * int.Parse(bigInteger[i].ToString()) + onePlusMind).ToString();//Без .ToString()
- if (singleDigit * int.Parse(bigInteger[i].ToString()) + onePlusMind > 9)
- {
- onePlusMind = int.Parse(multiplyByOneDigit[0].ToString());//Тогава onePlusMind ще е onePlusMind /= 10;
- result.Insert(0, multiplyByOneDigit[1]);//И също вместо multiplyByOneDigit[1] ще е (multiplyByOneDigit %10).ToString()
- if (i == 0)
- {
- result.Insert(0, onePlusMind.ToString()[0]);//Без .ToString()[0]
- }
- }
- else
- {
- onePlusMind = 0;
- result.Insert(0, multiplyByOneDigit[0]);//Без [0];
- }
- }
- Console.WriteLine(string.Join("", result));
- }
- }
Add Comment
Please, Sign In to add comment