Artem_Chepurov

Ex 2

Jun 15th, 2022 (edited)
334
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.44 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace SandBox
  6. {
  7.     struct Candidate
  8.     {
  9.         public string identifier;
  10.         public int countTask;
  11.         public int fine;
  12.     }
  13.     public class Program
  14.     {
  15.         static void Main(string[] args)
  16.         {
  17.             Dictionary<string, List<Candidate>> dictionaryVacancyCandidatesList = new Dictionary<string, List<Candidate>>();
  18.             Dictionary<string, int> maxCountCandidatesVacancy = new Dictionary<string, int>();
  19.            
  20.             int countVacancy = Convert.ToInt32(Console.ReadLine());
  21.             for (int i = 0; i < countVacancy; i++)
  22.             {
  23.                 string vacancyAndMaxCountCandidates = Console.ReadLine();
  24.                 string vacancy = vacancyAndMaxCountCandidates.Split(',')[0];
  25.                 int maxCountCandidates = Convert.ToInt32(vacancyAndMaxCountCandidates.Split(',')[1]);
  26.                 maxCountCandidatesVacancy.Add(vacancy, maxCountCandidates);
  27.                 dictionaryVacancyCandidatesList.Add(vacancy, new List<Candidate>());
  28.             }
  29.  
  30.             int countCandidates = Convert.ToInt32(Console.ReadLine());
  31.  
  32.             for (int i = 0; i < countCandidates; i++)
  33.             {
  34.                 string candidate = Console.ReadLine();
  35.                 string vacancy = candidate.Split(',')[1];
  36.                 dictionaryVacancyCandidatesList[vacancy].Add(new Candidate()
  37.                 {
  38.                     identifier = candidate.Split(',')[0],
  39.                     countTask = Convert.ToInt32(candidate.Split(',')[2]),
  40.                     fine = Convert.ToInt32(candidate.Split(',')[3])
  41.                 });
  42.             }
  43.  
  44.             List<string> candidatesList = new List<string>();
  45.             foreach (var keyValue in dictionaryVacancyCandidatesList)
  46.             {
  47.                 var sortedCandidate = from c in keyValue.Value
  48.                     orderby c.countTask descending, c.fine select c;
  49.                 List<Candidate> candidates = new List<Candidate>();
  50.                 candidates.AddRange(sortedCandidate.Take(maxCountCandidatesVacancy[keyValue.Key]));
  51.                 foreach (var c in candidates)
  52.                 {
  53.                     candidatesList.Add(c.identifier);
  54.                 }
  55.             }
  56.  
  57.             candidatesList.Sort();
  58.  
  59.             foreach (var c in candidatesList)
  60.             {
  61.                 Console.WriteLine(c);
  62.             }
  63.         }
  64.     }
  65. }
Add Comment
Please, Sign In to add comment