CS
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
using System;
using System.Collections.Generic;
using System.Linq;
//After many hours of effort and trying several methods, I solved all 6 of the six tests in the "longest common string" task.
public class Program
{
public static void Main()
{
string[] words = Console.ReadLine().
Split(' ');
Array.Sort(words, (x, y) =>
x.Length.CompareTo(y.Length));
string word = words[0];
int length = word.Length;
for (int i = length; i > 0; i--)
{
HashSet<string> substrings =
new HashSet<string>();
for (int j = 0;
j <= length - i; j++)
{
substrings.Add
(word.Substring(j, i));
}
Enter to Rename, Shift+Enter to Preview
OUTPUT
Запуск