Advertisement
Guest User

Untitled

a guest
Sep 17th, 2015
233
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.90 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace Problem_04
  6. {
  7.     class Program
  8.     {
  9.         static void Main()
  10.         {
  11.             string[] inputElements = Console.ReadLine().Split(' ').ToArray();
  12.             string tempStr = "";
  13.             tempStr = inputElements[0];
  14.  
  15.             for (int i = 0; i < inputElements.Length; i++)
  16.             {
  17.                 if (i < inputElements.Length-1)
  18.                 {
  19.                     if (inputElements[i] == inputElements[i + 1])
  20.                     {
  21.                         if (tempStr == "")
  22.                         {
  23.                             tempStr = inputElements[i];    
  24.                         }
  25.                        
  26.                         tempStr = tempStr + " " + inputElements[i + 1];
  27.  
  28.                         if (i == inputElements.Length-2)
  29.                         {
  30.                             Console.WriteLine(tempStr);
  31.                         }
  32.                     }
  33.                     else
  34.                     {
  35.                         if (tempStr == "")
  36.                         {
  37.                             tempStr = inputElements[i];
  38.                         }
  39.                         Console.WriteLine(tempStr);
  40.                         tempStr = "";
  41.                     }
  42.                 }
  43.                 else
  44.                 {
  45.                     if (inputElements.Length > 1 && (inputElements[inputElements.Length-1] != inputElements[inputElements.Length-2]))
  46.                     {
  47.                         tempStr = inputElements[inputElements.Length-1];
  48.                         Console.WriteLine(tempStr);
  49.                     }
  50.                     else if (inputElements.Length == 1)
  51.                     {
  52.                         tempStr = inputElements[i];
  53.                         Console.WriteLine(tempStr);
  54.                     }
  55.                 }
  56.             }
  57.         }
  58.     }
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement