-
Notifications
You must be signed in to change notification settings - Fork 7
/
Program.cs
38 lines (36 loc) · 1.28 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
using System;
using System.Collections.Generic;
using System.Linq;
namespace BeforeAndAfterPuzzle
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Hello World!");
}
static IList<string> BeforeAndAfterPuzzles(string[] phrases)
{
var set = new HashSet<string>();
var exceptFirst = new string[phrases.Length];
var exceptLast = new string[phrases.Length];
var splitWords = new string[phrases.Length][];
for (int i = 0; i < phrases.Length; i++)
{
splitWords[i] = phrases[i].Split(" ");
exceptFirst[i] = splitWords[i].Length == 1 ? splitWords[i][0] : string.Join(' ', splitWords[i]);
exceptLast[i] = splitWords[i].Length == 1 ? "" : string.Join(' ', splitWords[i][..^1]);
}
for (int i = 0; i < phrases.Length; i++)
{
for (int j = 0; j < phrases.Length; j++)
{
if(i == j) continue;
if (splitWords[i][^1] == splitWords[j][0])
set.Add((exceptLast[i] + " " + exceptFirst[j]).Trim());
}
}
return set.OrderBy(x => x).ToList();
}
}
}