WindFell

Char Multiply

Jun 20th, 2018
196
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.96 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.             result += firstText.Length > secondText.Length ? firstText[index] : secondText[index];
  33.         }
  34.  
  35.         return result;
  36.     }
  37. }
Advertisement
Add Comment
Please, Sign In to add comment