|
|
вернуться в форумWhat's wrong WA#9. Give me more tests using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Runtime.Serialization; using System.Runtime.Serialization.Formatters.Soap; using System.IO; namespace _2033 { class Device { public string Friend { get; set; } public string Name { get; set; } public int Cost { get; set; } } class Program { static void Main() {
List<Device> objList = new List<Device>(); for (int i = 0; i < 6; i++) objList.Add(new Device { Friend = Console.ReadLine(), Name = Console.ReadLine(), Cost = int.Parse(Console.ReadLine()) });
// 1. Находим девайс, который находится у большинства парней var query = from list in objList group list by list.Name into grouping orderby grouping.Count () descending where grouping.Count()>=2 select new {grouping.Key,PRCNT= grouping.Count ()} ; string Device = ""; int prev_cnt = 0; bool isFind = true; foreach (var item in query) { if (prev_cnt != 0 && item.PRCNT == prev_cnt) { isFind = false; break; } else if (prev_cnt >= 2 && item.PRCNT<prev_cnt) break; Device = item.Key; prev_cnt = item.PRCNT; } if (Device != "" && isFind) { Console.WriteLine(Device); return; }
//Если таких устройств несколько , то находим самое дешевое из них var query2 = objList.OrderBy(dev => dev.Cost); foreach (var item in query2) { Console.WriteLine(item.Name); return; } } } } |
|
|