Created
June 15, 2016 13:31
-
-
Save vdonchev/4d93d92d558de8496b840dccd48a495e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| namespace _01.JediMeditation | |
| { | |
| using System; | |
| using System.Collections.Generic; | |
| using System.Linq; | |
| public static class JediMeditation | |
| { | |
| private static readonly List<List<string>> OrderedJedis = new List<List<string>>(); | |
| private static bool yodaExists; | |
| public static void Main() | |
| { | |
| for (int i = 0; i < 4; i++) | |
| { | |
| OrderedJedis.Add(new List<string>()); | |
| } | |
| var linesCount = int.Parse(Console.ReadLine()); | |
| for (int i = 0; i < linesCount; i++) | |
| { | |
| var input = Console.ReadLine() | |
| .Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); | |
| foreach (var jedi in input) | |
| { | |
| var jediType = jedi[0]; | |
| switch (jediType) | |
| { | |
| case 'm': OrderedJedis[1].Add(jedi); break; | |
| case 'k': OrderedJedis[2].Add(jedi); break; | |
| case 'p': OrderedJedis[3].Add(jedi); break; | |
| case 's': | |
| case 't': | |
| OrderedJedis[0].Add(jedi); | |
| break; | |
| default: yodaExists = true; break; | |
| } | |
| } | |
| } | |
| if (yodaExists) | |
| { | |
| var temp = OrderedJedis[0]; | |
| OrderedJedis.RemoveAt(0); | |
| OrderedJedis.Insert(2, temp); | |
| } | |
| Console.WriteLine(string.Join(" ", OrderedJedis.SelectMany(list => list))); | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment