tcetso

Untitled

Apr 6th, 2017
324
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.43 KB | None | 0 0
  1. using System;
  2.  
  3. namespace DataTypesExercises
  4.     {
  5.     class Exercises
  6.         {
  7.         static void Main()
  8.             {
  9.             int wordsCount = int.Parse(Console.ReadLine());
  10.             string output = string.Empty;
  11.             string previousWord = string.Empty;
  12.             bool toEnd = true;
  13.             for (int i = 0; i < wordsCount; i++)
  14.                 {
  15.                 string currentWord = Console.ReadLine();
  16.                 if (currentWord == "spin")
  17.                     {
  18.                     toEnd = !toEnd;
  19.                     i--;
  20.                     }
  21.                 switch (toEnd)
  22.                     {
  23.                     case (true): output += currentWord; break;
  24.                     case (false): output = currentWord + output; break;
  25.                     }
  26.                 if (currentWord == previousWord)
  27.                     {
  28.                     output = string.Empty;
  29.                     if (currentWord == "spin")
  30.                         {
  31.                         toEnd = !toEnd; //<- Why if i have two or more consecutive times spin I have to leave the direction the way it was before the first "spin"
  32.                         }
  33.                     previousWord = currentWord;
  34.                     }
  35.  
  36.                 previousWord = currentWord;
  37.                 }
  38.             output = output.Replace("spin", string.Empty);
  39.             Console.WriteLine(output);
  40.             }
  41.         }
  42.     }
Advertisement
Add Comment
Please, Sign In to add comment