Advertisement
Guest User

SequenceEqualElements

a guest
Sep 16th, 2015
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.46 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. class SeqEqualElements
  6. {
  7.     static void Main()
  8.     {
  9.         List<string> inputText = Console.ReadLine().Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).ToList();
  10.  
  11.         List<List<string>> sequences = new List<List<string>>();
  12.         List<string> currentSeq = new List<String>();
  13.  
  14.         if (inputText.Count == 1)
  15.         {
  16.             Console.WriteLine(inputText[0]);
  17.         }
  18.         else
  19.         {
  20.             for (int i = 0; i < inputText.Count - 1; i++)
  21.             {
  22.                 if (inputText[i].Equals(inputText[i + 1]))
  23.                 {
  24.                     currentSeq.Add(inputText[i]);
  25.                 }
  26.                 else
  27.                 {
  28.                     currentSeq.Add(inputText[i]);
  29.                     sequences.Add(new List<string>(currentSeq));
  30.                     currentSeq.Clear();
  31.                 }
  32.                 if (i == inputText.Count - 2)
  33.                 {
  34.                     currentSeq.Add(inputText[i + 1]);
  35.                     sequences.Add(new List<String>(currentSeq));
  36.                 }
  37.             }
  38.             PrintSequences(sequences);
  39.         }
  40.     }
  41.  
  42.     static void PrintSequences(List<List<string>> sequences)
  43.     {
  44.         foreach (List<string> sequence in sequences)
  45.         {
  46.             foreach (string element in sequence)
  47.             {
  48.                 Console.Write(element + " ");
  49.             }
  50.             Console.WriteLine();
  51.         }
  52.     }
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement