WindFell

Char Multiply

Jun 20th, 2018
180
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.09 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3.  
  4. class CharachterMultiplier
  5. {
  6.     static void Main(string[] args)
  7.     {
  8.         string[] input = Console.ReadLine()
  9.             .Split()
  10.             .ToArray();
  11.  
  12.         string firstText = input[0];
  13.         string secondText = input[1];
  14.         int result = Multiply(firstText, secondText);
  15.  
  16.         Console.WriteLine(result);
  17.     }
  18.  
  19.     static int Multiply(string firstText, string secondText)
  20.     {
  21.         int minLength = Math.Min(firstText.Length, secondText.Length);
  22.         int maxLength = Math.Max(firstText.Length, secondText.Length);
  23.         int result = 0;
  24.  
  25.         for (int index = 0; index < minLength; index++)
  26.         {
  27.             result += firstText[index] * secondText[index];
  28.         }
  29.  
  30.         for (int index = minLength; index < maxLength; index++)
  31.         {
  32.             if (firstText.Length > secondText.Length)
  33.             {
  34.                 result += firstText[index];
  35.             }
  36.             else
  37.             {
  38.                 result += secondText[index];
  39.             }
  40.         }
  41.  
  42.         return result;
  43.     }
  44. }
Advertisement
Add Comment
Please, Sign In to add comment