Loading...
Elena123456 avatar Elena123456 235 Точки

02. Judge - Associative Arrays - More Exercise (83/100)

Does somebody know which are the tests #3 and #4 from this exercise?

With given inputs my outputs are correct, but Judge has given me 83/100.

Can somebody please help me again?

https://softuni.bg/trainings/resources/officedocument/38560/more-exercise-technology-fundamentals-with-csharp-january-2019/2237

https://judge.softuni.bg/Contests/Practice/Index/1302#1

 

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

namespace dictionary
{
    class Program
    {
        static void Main(string[] args)
        {
            var contestsWithUsernameAndPoints = new Dictionary<string, Dictionary<string, int>>();
            var usernamesAndTotalPoints = new Dictionary<string, int>();
            string input = string.Empty;
            while ((input = Console.ReadLine()) != "no more time")
            {
                string[] inputArray = input.Split(" -> ");
                string username = inputArray[0];
                string contest = inputArray[1];
                int points = int.Parse(inputArray[2]);

                if (contestsWithUsernameAndPoints.ContainsKey(contest) == false)
                {
                    if (usernamesAndTotalPoints.ContainsKey(username) == false)
                    {
                        contestsWithUsernameAndPoints[contest] = new Dictionary<string, int>();
                        contestsWithUsernameAndPoints[contest].Add(username, points);
                        usernamesAndTotalPoints[username] = points;
                    }

                    else if (usernamesAndTotalPoints.ContainsKey(username) == true)
                    {
                        contestsWithUsernameAndPoints[contest] = new Dictionary<string, int>();
                        contestsWithUsernameAndPoints[contest].Add(username, points);
                        usernamesAndTotalPoints[username] += points;
                    }
                }

                else if (contestsWithUsernameAndPoints.ContainsKey(contest) == true)
                {
                    if (usernamesAndTotalPoints.ContainsKey(username) == false)
                    {
                        contestsWithUsernameAndPoints[contest].Add(username, points);
                        usernamesAndTotalPoints[username] = points;
                    }

                    else if (usernamesAndTotalPoints.ContainsKey(username) == true)
                    {
                        bool theUserAlreadyExistInContest = false;
                        foreach (var kvp in contestsWithUsernameAndPoints[contest])
                        {
                            string currentUsername = kvp.Key;
                            int currentPoints = kvp.Value;

                            if (currentUsername == username && points > currentPoints)
                            {
                                theUserAlreadyExistInContest = true;
                                contestsWithUsernameAndPoints[contest][username] = points;//entry in contest and then in the username value
                                usernamesAndTotalPoints[username] -= currentPoints;
                                usernamesAndTotalPoints[username] += points;
                                theUserAlreadyExistInContest = true;
                                break;
                            }
                        }

                        if(theUserAlreadyExistInContest == false)
                        {
                            contestsWithUsernameAndPoints[contest].Add(username, points);
                            usernamesAndTotalPoints[username] += points;
                        }
                    }
                }
            }


            foreach (var kvp in contestsWithUsernameAndPoints)
            {
                string contest = kvp.Key;
                var usernameAndPointsDictionary = kvp.Value;
                int k = 1;
                Console.WriteLine($"{contest}: {contestsWithUsernameAndPoints[contest].Count()} participants");
                foreach (var usernameAndPoints in contestsWithUsernameAndPoints[contest].OrderByDescending(x => x.Value)
                                                                                        .ThenBy(x => x.Key))
                {
                    string username = usernameAndPoints.Key;
                    int points = usernameAndPoints.Value;
                    Console.WriteLine($"{k}. {username} <::> {points}");
                    k++;

                }
            }

            Console.WriteLine("Individual standings:");
            int i = 1;
            foreach (var kvp in usernamesAndTotalPoints.OrderByDescending(x=>x.Value).ThenBy(x=>x.Key))
            {
                string username = kvp.Key;
                int totalPoints = kvp.Value;
                Console.WriteLine($"{i}. {username} -> {totalPoints}");
                i++;
            }

        }
    }
}

 

0
C# Fundamentals 07/11/2020 14:18:58
Elena123456 avatar Elena123456 235 Точки

While I was doing another exercise (MOBA Challenger) I have founded my mistake in this exercise. :)

Those lines are incorrect:

if (currentUsername == username && points > currentPoints)
                            {
                                theUserAlreadyExistInContest = true;
                                contestsWithUsernameAndPoints[contest][username] = points;//entry in contest and then in the username value
                                usernamesAndTotalPoints[username] -= currentPoints;
                                usernamesAndTotalPoints[username] += points;
                                theUserAlreadyExistInContest = true;
                                break;
                            }

 

Correct lines:

 if (currentUsername == username)
                            {
                                theUserAlreadyExistInContest = true;
                                if (points > currentPoints)
                                {
                                    contestsWithUsernameAndPoints[contest][username] = points;//entry in contest and then in the username value
                                    usernamesAndTotalPoints[username] -= currentPoints;
                                    usernamesAndTotalPoints[username] += points;
                                    theUserAlreadyExistInContest = true;
                                    break;
                                }
                            }

 

In the first case theUserAlreadyExistInContest=true only when currentUsername == username && points > currentPoints, but this is incorrect. theUserAlreadyExistInContest=true when currentUsername == username and then we should check the points.

https://pastebin.com/8jpWtTVz - 100/100

I want to thank everybody who took time to read my question. :)

2
07/11/2020 23:28:47
Можем ли да използваме бисквитки?
Ние използваме бисквитки и подобни технологии, за да предоставим нашите услуги. Можете да се съгласите с всички или част от тях.
Назад
Функционални
Използваме бисквитки и подобни технологии, за да предоставим нашите услуги. Използваме „сесийни“ бисквитки, за да Ви идентифицираме временно. Те се пазят само по време на активната употреба на услугите ни. След излизане от приложението, затваряне на браузъра или мобилното устройство, данните се трият. Използваме бисквитки, за да предоставим опцията „Запомни Ме“, която Ви позволява да използвате нашите услуги без да предоставяте потребителско име и парола. Допълнително е възможно да използваме бисквитки за да съхраняваме различни малки настройки, като избор на езика, позиции на менюта и персонализирано съдържание. Използваме бисквитки и за измерване на маркетинговите ни усилия.
Рекламни
Използваме бисквитки, за да измерваме маркетинг ефективността ни, броене на посещения, както и за проследяването дали дадено електронно писмо е било отворено.