Професионална програма
+ Нов въпрос
v.angelov92 avatar v.angelov92 6 Точки

Problem 8.*Ranking

Здравейте, на задача Problem 8. Ranking от Sets and Dictionaries Advanced - Exercise стигам до 40/100. Не мога да измисля как да направя следната проверка: If you receive the same contest and the same user, update the points only if the new ones are more than the older ones.

Бих се радвал, ако дадете решение как да принтирам най-добрия юзър и точки без да правя нов речник. Благодаря.

Код на задачата: https://pastebin.com/cEKbdppP

Линк в джъдж: https://judge.softuni.bg/Contests/Practice/Index/1466#7

Условие на задачата:

Problem 1.       *Ranking

Write a program that ranks candidate-interns, depending on the points from the interview tasks and their exam results in SoftUni. You will receive some lines of input in the format "{contest}:{password for contest}" until you receive "end of contests". Save that data because you will need it later. After that you will receive other type of inputs in format "{contest}=>{password}=>{username}=>{points}" until you receive "end of submissions". Here is what you need to do:

  • Check if the contest is valid (if you received it in the first type of input)
  • Check if the password is correct for the given contest
  • Save the user with the contest they take part in (a user can take part in many contests)and the points the user has in the given contest. If you receive the same contest and the same user, update the points only if the new ones are more than the older ones.

At the end you have to print the info for the user with the most points in the format:

"Best candidate is {user} with total {total points} points.". After that print all students ordered by their names. For each user, print each contest with the points in descending order in the following format:

"{user1 name}

#  {contest1} -> {points}

#  {contest2} -> {points}

{user2 name}




  • You will be receiving strings in formats described above, until the appropriate commands, also described above, are given.             


  • On the first line print the best user in the format described above.
  • On the next lines print all students ordered as mentioned above in format.


  • There will be no case with two equal contests.
  • The strings may contain any character except
  • The numbers will be in range [0 - 10000].
  • The second input is always valid.
  • There will be no case with 2 or more users with same total points.




Part One Interview:success

Js Fundamentals:Pesho

C# Fundamentals:fundPass


end of contests

C# Fundamentals=>fundPass=>Tanya=>350


Part One Interview=>success=>Nikola=>120

Java Basics Exam=>pesho=>Petkan=>400

Part One Interview=>success=>Tanya=>220

OOP Advanced=>password123=>BaiIvan=>231

C# Fundamentals=>fundPass=>Tanya=>250

C# Fundamentals=>fundPass=>Nikola=>200

Js Fundamentals=>Pesho=>Tanya=>400

end of submissions

Best candidate is Tanya with total 1350 points.



#  C# Fundamentals -> 200

#  Part One Interview -> 120


#  Js Fundamentals -> 400

#  Algorithms -> 380

#  C# Fundamentals -> 350

#  Part One Interview -> 220

Java Advanced:funpass

Part Two Interview:success

Math Concept:asdasd

Java Web Basics:forrF

end of contests

Math Concept=>ispass=>Monika=>290

Java Advanced=>funpass=>Simona=>400

Part Two Interview=>success=>Drago=>120

Java Advanced=>funpass=>Petyr=>90

Java Web Basics=>forrF=>Simona=>280

Part Two Interview=>success=>Petyr=>0

Math Concept=>asdasd=>Drago=>250

Part Two Interview=>success=>Simona=>200

end of submissions

Best candidate is Simona with total 880 points.



#  Math Concept -> 250

#  Part Two Interview -> 120


#  Java Advanced -> 90

#  Part Two Interview -> 0


#  Java Advanced -> 400

#  Java Web Basics -> 280

#  Part Two Interview -> 200

Module: C# Advanced
Axiomatik avatar Axiomatik 1169 Точки

Code is fine, just needed to use OrderByDescending to find the best candidate, however you are missing out one validation which is why you only receive 60%. If you complete the last validation you should get 100%.


using System;
using System.Linq;
using System.Collections.Generic;

namespace Exam
    class Program
        static void Main(string[] args)
            var listOfContests = new Dictionary<string, string>();
            var bestCandidate = new Dictionary<string, Dictionary<string, int>>();
            var listResult = new Dictionary<string, int>();

            while (true)
                var input = Console.ReadLine().Split(':').ToArray();

                if (input[0] == "end of contests")

                var contest = input[0];
                var passwordForContest = input[1];

                listOfContests.Add(contest, passwordForContest);

            while (true)
                var input = Console.ReadLine().Split("=>").ToArray();

                if (input[0] == "end of submissions")

                var contest = input[0];
                var password = input[1];
                var user = input[2];
                var points = int.Parse(input[3]);

                if (listOfContests.ContainsKey(contest))
                    if (listOfContests[contest].Contains(password))
                        if (!bestCandidate.ContainsKey(user))
                            bestCandidate.Add(user, new Dictionary<string, int>());
                            listResult.Add(user, points);
                            bestCandidate[user].Add(contest, points);
                        else if (bestCandidate.ContainsKey(user))
                            // MISSING VALIDATION
                            //Save the user with the contest they take part in
                            //(a user can take part in many contests) and the points
                            //the user has in the given contest.If you receive the same
                            //contest and the same user update the points only if the new ones are
                            //more than the older ones.
                        else if (!bestCandidate[user].ContainsKey(contest))
                            bestCandidate[user].Add(contest, points);
                            listResult[user] += points;

            foreach (var (key, value) in listResult.OrderByDescending(x => x.Value).Take(1))
                Console.WriteLine($"Best candidate is {key} with total {value} points.");


            foreach (var (key, value) in bestCandidate.OrderBy(x => x.Key))

                foreach (var (contest, points) in value.OrderByDescending(x => x.Value))
                    Console.WriteLine($"#  {contest} -> {points}");