LachezarNinkov

Untitled

Jun 20th, 2017
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.95 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3. namespace Last3ConsecutiveEqualStrings
  4. {
  5.     class Last3ConsecutiveEqualStrings
  6.     {
  7.         static void Main()
  8.         {
  9.  
  10.             string[] inputArr = Console.ReadLine()
  11.                 .Split(' ');
  12.             int count = 1;
  13.             string word = string.Empty;
  14.  
  15.             for (int i = inputArr.Length - 1; i > 0; i--)
  16.             {
  17.                 word = inputArr[i];
  18.                 if (inputArr[i] == inputArr[i - 1])
  19.                 {
  20.                     count++;
  21.                     if (count == 3)
  22.                     {
  23.  
  24.                         for (int j = 0; j < count; j++)
  25.                         {
  26.  
  27.                             Console.Write($"{word} ");
  28.                         }
  29.                         break;
  30.                     }
  31.                 }
  32.                 else
  33.                 {
  34.                     count = 1;
  35.  
  36.                 }
  37.             }
  38.         }
  39.  
  40.  
  41.     }
  42. }
Advertisement
Add Comment
Please, Sign In to add comment