Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- class SeqEqualElements
- {
- static void Main()
- {
- List<string> inputText = Console.ReadLine().Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).ToList();
- List<List<string>> sequences = new List<List<string>>();
- List<string> currentSeq = new List<String>();
- if (inputText.Count == 1)
- {
- Console.WriteLine(inputText[0]);
- }
- else
- {
- for (int i = 0; i < inputText.Count - 1; i++)
- {
- if (inputText[i].Equals(inputText[i + 1]))
- {
- currentSeq.Add(inputText[i]);
- }
- else
- {
- currentSeq.Add(inputText[i]);
- sequences.Add(new List<string>(currentSeq));
- currentSeq.Clear();
- }
- if (i == inputText.Count - 2)
- {
- currentSeq.Add(inputText[i + 1]);
- sequences.Add(new List<String>(currentSeq));
- }
- }
- PrintSequences(sequences);
- }
- }
- static void PrintSequences(List<List<string>> sequences)
- {
- foreach (List<string> sequence in sequences)
- {
- foreach (string element in sequence)
- {
- Console.Write(element + " ");
- }
- Console.WriteLine();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement