-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProgram.cs
39 lines (33 loc) · 1.11 KB
/
Program.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
using System;
using System.Linq;
namespace CharacterMultiplier
{
class Program
{
static void Main(string[] args)
{
string[] input = Console.ReadLine().Split(' ').ToArray();
long multiplier = CharacterMultiply(input[0], input[1]);
Console.WriteLine(multiplier);
}
public static long CharacterMultiply(string firstString, string secondString)
{
long sum = 0;
string stringOne = firstString;
string stringTwo = secondString;
string[] strings = {stringOne, stringTwo};
int shortestLength = strings.Min(x => x.Length);
int longestLength = strings.Max(x => x.Length);
for (int i = 0; i < shortestLength; i++)
{
sum += stringOne[i] * stringTwo[i];
}
string longestString = strings.FirstOrDefault(x => x.Length == longestLength);
for (int i = shortestLength; i < longestLength; i++)
{
sum += longestString[i];
}
return sum;
}
}
}