Advertisement
JulianJulianov

07.TextProcessingExercise-Character Multiplier

Apr 17th, 2020
441
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.71 KB | None | 0 0
  1. 02.Character Multiplier
  2. Create a method that takes two strings as arguments and returns the sum of their character codes multiplied (multiply str1[0] with str2[0] and add to the total sum). Then continue with the next two characters. If one of the strings is longer than the other, add the remaining character codes to the total sum without multiplication.
  3. Examples
  4. Input                 Output
  5. Gosho Pesho           53253
  6. 123 522               7647
  7. a aaaa                9700
  8.  
  9. using System;
  10.  
  11. namespace ExamResults
  12. {
  13.     class Program
  14.     {
  15.         static void Main(string[] args)
  16.         {
  17.             var twoStrigs = Console.ReadLine().Split();//1
  18.             int finalSum = ASCII(twoStrigs[0], twoStrigs[1]);//2.Ctrl + . + Enter = //4.Method
  19.             Console.WriteLine(finalSum);//3      
  20.         }
  21.         public static int ASCII(string firstString, string secondString)//4.Rename "private" to "public", защото така става достъпен!
  22.         {
  23.             var count = 0;
  24.             int totalSum = 0;
  25.             int remainingSum = 0;
  26.             if (firstString.Length > secondString.Length)
  27.             {
  28.                 count = secondString.Length;
  29.                 for (int i = count; i < firstString.Length; i++)
  30.                 {
  31.                     remainingSum += firstString[i];
  32.                 }
  33.             }
  34.             else
  35.             {
  36.                 count = firstString.Length;
  37.                 for (int i = count; i < secondString.Length; i++)
  38.                 {
  39.                     remainingSum += secondString[i];
  40.                 }
  41.             }
  42.             for (int i = 0; i < count; i++)
  43.             {
  44.                 int multiply = firstString[i] * secondString[i];
  45.                 totalSum += multiply;
  46.             }
  47.             return totalSum += remainingSum;//5.Write "return", защото ще връщам данни!
  48.         }
  49.     }
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement