Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 02.Character Multiplier
- 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.
- Examples
- Input Output
- Gosho Pesho 53253
- 123 522 7647
- a aaaa 9700
- using System;
- namespace ExamResults
- {
- class Program
- {
- static void Main(string[] args)
- {
- var twoStrigs = Console.ReadLine().Split();//1
- int finalSum = ASCII(twoStrigs[0], twoStrigs[1]);//2.Ctrl + . + Enter = //4.Method
- Console.WriteLine(finalSum);//3
- }
- public static int ASCII(string firstString, string secondString)//4.Rename "private" to "public", защото така става достъпен!
- {
- var count = 0;
- int totalSum = 0;
- int remainingSum = 0;
- if (firstString.Length > secondString.Length)
- {
- count = secondString.Length;
- for (int i = count; i < firstString.Length; i++)
- {
- remainingSum += firstString[i];
- }
- }
- else
- {
- count = firstString.Length;
- for (int i = count; i < secondString.Length; i++)
- {
- remainingSum += secondString[i];
- }
- }
- for (int i = 0; i < count; i++)
- {
- int multiply = firstString[i] * secondString[i];
- totalSum += multiply;
- }
- return totalSum += remainingSum;//5.Write "return", защото ще връщам данни!
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement