using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace _23._02._2020 { class Program { static bool isLetter(char a) { return (a >= 'A' && a <= 'Z') || (a >= 'a' && a <= 'z'); } static Dictionary getStrings(string text) { string temp = ""; int startPosition = -1; Dictionary strings = new Dictionary(); for (int i = 0; i < text.Length; i++) { if (isLetter(text[i])) { temp += text[i]; if (startPosition < 0) startPosition = i; } else { if (temp != "") strings.Add(startPosition, temp); temp = ""; startPosition = -1; } } if (temp != "") strings.Add(startPosition, temp); return strings; } static void Main(string[] args) { string text = Console.ReadLine(); string temp = ""; Dictionary strings = new Dictionary(); Dictionary sortedStrings = new Dictionary(); Dictionary seqStr = new Dictionary(); Dictionary startEnds = new Dictionary(); strings = getStrings(text); foreach (var pair in strings.OrderBy(key => key.Value)) { sortedStrings.Add(pair.Key, pair.Value); //Console.WriteLine(pair.Key + " " + pair.Value); } for (int i = 0; i < sortedStrings.Count - 1; i++) { KeyValuePair pair = new KeyValuePair(sortedStrings.Keys.ElementAt(i), sortedStrings.Values.ElementAt(i)); var nextPair = new KeyValuePair(sortedStrings.Keys.ElementAt(i + 1), sortedStrings.Values.ElementAt(i + 1)); if (pair.Value == nextPair.Value) { if (!seqStr.ContainsKey(pair.Key)) seqStr.Add(pair.Key, pair.Value); if (!seqStr.ContainsKey(nextPair.Key)) seqStr.Add(nextPair.Key, nextPair.Value); } } int lastindex = -1; for (int i = 0; i < seqStr.Count - 1; i++) { KeyValuePair pair = new KeyValuePair(seqStr.Keys.ElementAt(i), seqStr.Values.ElementAt(i)); KeyValuePair nextPair = new KeyValuePair(seqStr.Keys.ElementAt(i + 1), seqStr.Values.ElementAt(i + 1)); if (lastindex < 0) lastindex = pair.Key; if (pair.Value != nextPair.Value) { Console.WriteLine(pair.Value + " - " + nextPair.Value); startEnds.Add(lastindex, pair.Key); lastindex = -1; } if (i == seqStr.Count - 2) { startEnds.Add(lastindex, nextPair.Key); } } foreach (var pair in seqStr) { Console.WriteLine(pair.Key + " " + pair.Value); } foreach (var pair in startEnds) { Console.WriteLine(pair.Key + " " + pair.Value); } } } }