ENG  RUSTimus Online Judge
Online Judge
Задачи
Авторы
Соревнования
О системе
Часто задаваемые вопросы
Новости сайта
Форум
Ссылки
Архив задач
Отправить на проверку
Состояние проверки
Руководство
Регистрация
Исправить данные
Рейтинг авторов
Текущее соревнование
Расписание
Прошедшие соревнования
Правила
вернуться в форум

Обсуждение задачи 1612. Трамвайный форум

AC Solution C#: Use Linq
Послано Hikmat Ahmedov 9 мар 2012 00:12
// ----------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");
    }
}