ENG  RUS Timus Online Judge
Online Judge
Problems
Authors
Online contests
Site news
Webboard
Problem set
Submit solution
Judge status
Guide
Register
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

## Discussion of Problem 2033. Devices

What's wrong WA#9. Give me more tests
Posted by novopashinwm 26 Aug 2016 16:32
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++)

// 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;
}
}
}
}