Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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<int, string> getStrings(string text)
- {
- string temp = "";
- int startPosition = -1;
- Dictionary<int, string> strings = new Dictionary<int, string>();
- 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<int, string> strings = new Dictionary<int, string>();
- Dictionary<int, string> sortedStrings = new Dictionary<int, string>();
- Dictionary<int, string> seqStr = new Dictionary<int, string>();
- Dictionary<int, int> startEnds = new Dictionary<int, int>();
- 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<int, string> pair = new KeyValuePair<int, string>(sortedStrings.Keys.ElementAt(i), sortedStrings.Values.ElementAt(i));
- var nextPair = new KeyValuePair<int, string>(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<int, string> pair = new KeyValuePair<int, string>(seqStr.Keys.ElementAt(i), seqStr.Values.ElementAt(i));
- KeyValuePair<int, string> nextPair = new KeyValuePair<int, string>(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);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement