stefan1919

Sequences of Equal Strings

Sep 8th, 2015
156
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.25 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace ConsoleApplication6
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             string[] input = Console.ReadLine().Split(' ');
  14.             List<string> listInput = new List<string>();
  15.             listInput = input.ToList();
  16.             int count = listInput.Count;
  17.             int checker = 0;
  18.             while (count > 0)
  19.             {
  20.                 List<string> currentWord = new List<string>();
  21.                 string word = listInput[0];
  22.                 listInput.RemoveAt(0);
  23.                 currentWord.Add(word);
  24.                for (int i = 0; i < listInput.Count; i++)
  25.             {
  26.                 if (word == listInput[i])
  27.                 {
  28.                     currentWord.Add(listInput[i]);
  29.                     listInput.RemoveAt(i);
  30.                     i--;
  31.                 }
  32.             }
  33.                count -= currentWord.Count;
  34.                foreach (var item in currentWord)
  35.                {
  36.                    Console.Write(item + " ");
  37.                }
  38.                Console.WriteLine();
  39.                checker++;
  40.             }
  41.             }
  42.         }
  43.     }
Advertisement
Add Comment
Please, Sign In to add comment