Advertisement
Daniel_007

02. Character Multiplier

Mar 20th, 2020
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.12 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace  02. Character Multiplier
  6. {
  7.     class Program
  8.     {
  9.         static void Main(string[] args)
  10.         {
  11.             string[] word = Console.ReadLine().Split().ToArray();
  12.             string firstWord = word[1];
  13.             string secondWord = word[0];
  14.             if (word[0].Length >= word[1].Length)
  15.             {
  16.                 firstWord = word[0];
  17.                 secondWord = word[1];
  18.             }
  19.  
  20.             int minWordLenght = Math.Min(word[0].Length, word[1].Length);
  21.             int maxWordLenght = Math.Max(word[0].Length, word[1].Length);
  22.             int sum = 0;
  23.             for (int i = 0; i < minWordLenght; i++)
  24.             {
  25.                 char firstLetter = firstWord[i];
  26.                 char secondLetter = secondWord[i];
  27.                 sum += firstLetter * secondLetter;
  28.             }
  29.             for (int i = minWordLenght; i < maxWordLenght; i++)
  30.             {
  31.                 char firstLetter = firstWord[i];
  32.                 sum += firstLetter;
  33.             }
  34.             Console.WriteLine(sum);
  35.         }
  36.     }
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement