Advertisement
YavorGrancharov

Character_Multiplier

Oct 27th, 2017
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.01 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3.  
  4. namespace Character_Multiplier
  5. {
  6.     class Program
  7.     {
  8.         static void Main(string[] args)
  9.         {
  10.             string[] input = Console.ReadLine().Split().ToArray();
  11.             Console.WriteLine(multiplier(input));
  12.         }
  13.         static int multiplier(string[] input)
  14.         {
  15.             string left = input[0];
  16.             string right = input[1];
  17.  
  18.             int min = Math.Min(left.Length, right.Length);
  19.             int max = Math.Max(left.Length, right.Length);
  20.  
  21.             int result = 0;
  22.  
  23.             for (int i = 0; i < min; i++)
  24.             {
  25.                 result += left[i] * right[i];
  26.             }
  27.  
  28.             if (left.Length != right.Length)
  29.             {
  30.                 string longer = left.Length > right.Length ? longer = left : longer = right;
  31.                 for (int i = min; i < max; i++)
  32.                 {
  33.                     result += longer[i];
  34.                 }
  35.             }
  36.             return result;
  37.         }
  38.     }
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement