|
|
back to boardAC Solution C#: Use Linq // ----------SOLVED------------ using System; using System.Collections.Generic; using System.Linq; class Program { static void Main() { /* Here we include all word separators */ string[] ss = Console.In.ReadToEnd().Split(new char[] { ' ', '\t', '\n', '\r','.',',','!','?','-',':'}, StringSplitOptions.RemoveEmptyEntries); /* From the word list select just "tram" and "trolleybus" by Grouping we know how many times these words appear by ordering we make sure that "tram" comes first in the list r[] if both words appear in the input */ var r = (from u in ss where u == "tram" || u == "trolleybus" group u by u into uu orderby uu.Key select new { key=uu.Key, count=uu.Count() } ).ToList(); /* The rest is just printing the output basing on the results of the query */ if (r.Count == 0) Console.WriteLine("Bus driver"); else if (r.Count == 1) Console.WriteLine("{0}", r[0].key == "tram" ? "Tram driver" : "Trolleybus driver"); else if (r[0].count > r[1].count) Console.WriteLine("Tram driver"); else if (r[0].count < r[1].count) Console.WriteLine("Trolleybus driver"); else Console.WriteLine("Bus driver"); } } |
|
|