Advertisement
grubcho

Last 3 consecutive equal strings

Jun 20th, 2017
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.85 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 Last_3_Consecutive_Equal_Strings
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             string[] input = Console.ReadLine().Split(' ');
  14.             int count = 1;
  15.             for (int i = input.Length-1; i > 0; i--)
  16.             {
  17.                 if (input[i] == input[i-1])
  18.                 {
  19.                     count++;
  20.                     if (count == 3)
  21.                     {
  22.                         Console.WriteLine($"{input[i]} {input[i]} {input[i]}");
  23.                         break;
  24.                     }
  25.                 }
  26.                 else
  27.                 {
  28.                     count = 1;
  29.                 }                
  30.             }            
  31.         }
  32.     }
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement