LardaX

Character-Multiplier

Oct 18th, 2016
222
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.46 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace Character_Multiplier
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             string[] input = Console.ReadLine().Split();
  14.             string firstString = input[0];
  15.             string secondString = input[1];
  16.  
  17.             int result = GetMultipliedSumOfChars(firstString, secondString);
  18.  
  19.             Console.WriteLine(result);
  20.         }
  21.  
  22.         private static int GetMultipliedSumOfChars(string firstString, string secondString)
  23.         {
  24.             int sum = 0;
  25.  
  26.             if (firstString.Length >= secondString.Length)
  27.             {
  28.                 for (int i = 0; i < secondString.Length; i++)
  29.                 {
  30.                     sum += firstString[i] * secondString[i];
  31.                 }
  32.  
  33.                 for (int i = secondString.Length; i < firstString.Length; i++)
  34.                 {
  35.                     sum += firstString[i];
  36.                 }
  37.             }
  38.             else
  39.             {
  40.                 for (int i = 0; i < firstString.Length; i++)
  41.                 {
  42.                     sum += firstString[i] * secondString[i];
  43.                 }
  44.  
  45.                 for (int i = firstString.Length; i < secondString.Length; i++)
  46.                 {
  47.                     sum += secondString[i];
  48.                 }
  49.             }
  50.  
  51.             return sum;
  52.         }
  53.     }
  54. }
Advertisement
Add Comment
Please, Sign In to add comment