Advertisement
Spocoman

02. Character Multiplier

Apr 15th, 2023
743
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.79 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3. using System.Collections.Generic;
  4. using System.Text;
  5.  
  6. namespace CharacterMultiplier
  7. {
  8.  
  9.     class Program
  10.     {
  11.         static void Main()
  12.         {
  13.             Console.WriteLine(CharMultiplier(Console.ReadLine()));
  14.         }
  15.  
  16.         static int CharMultiplier(string text)
  17.         {
  18.             var words = text.Split().OrderBy(x => x.Length).ToList();
  19.             var firstWord = Encoding.ASCII.GetBytes(words[0]).ToList();
  20.             var secondWord = Encoding.ASCII.GetBytes(words[1]).ToList();
  21.             int result = 0;
  22.  
  23.             for (int i = 0; i < secondWord.Count(); i++)
  24.             {
  25.                 result += secondWord[i] * (i < firstWord.Count ? firstWord[i] : 1);
  26.             }
  27.  
  28.             return result;
  29.         }
  30.     }
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement