Loading...

Във форума е въведено ограничение, което позволява на потребителите единствено да разглеждат публикуваните въпроси.

sashotoka avatar sashotoka 2 Точки

Messages Manager от Programming Fundamentals Final Exam - 03 August 2019 Group 1

Здравейте, 

някакви идеи защо гърми на тест 9 и дава 91/100 ?

кода : https://pastebin.com/iAMBp22h

judge : https://judge.softuni.bg/Contests/Practice/Index/1748#2

условие :

Messages Manager

Create a program that manages messages sent and received of users. You need to keep information about username, their sent and received messages. You will receive the capacity of possible messages kept at once per user. You will be receiving lines with commands until you receive the "Statistics" command.  There are three possible commands:

  • "Add={username}={sent}={received}":
    • Add the username, his/her sent and received messages to your records. If person with the given username already exists ignore the line.
  • "Message={sender}={receiver}":
    • Check if both usernames exist and if they do, increase the sender’s sent messages by 1 and the receiver’s received messages by 1. If anyone reaches the capacity (first check the sender), he/she should be removed from the record and you should print the following message:
      • "{username} reached the capacity!"
  • "Empty={username}":
    • Delete all records of the given user, if he exists. If "All" is given as username - delete all records you have.

In the end, you have to print the count of users, each person with his/her messages (the count of both sent and received) sorted in descending order by the received messages and then by their username in ascending order in the following format:  

Users count: {count}

{username} - {messages}

{username} - {messages}

Input

  • On the first line, you will receive the capacity - an integer number in the range [1-10000].
  • You will be receiving lines until you receive the "Statistics" command.
  • The initial messages (sent and received) will always be below the capacity.
  • The input will always be valid.

Output

  • Print the appropriate message after the "Message" command, if someone reaches the capacity.
  • Print the users with their messages in the format described above.

 

 

Examples

Input

Output

10
Add=Mark=5=4
Add=Clark=3=5
Add=Berg=9=0
Add=Kevin=0=0
Message=Berg=Kevin
Statistics
 

Berg reached the capacity!

Users count: 3

Clark - 8

Mark - 9

Kevin - 1

Comments

First, we receive the capacity (10). Then we start receiving commands. The first four commands are for adding new users, so we do it. Then we have the command “Message=Berg=Kevin” and Berg reached the capacity, so we remove him, but Kevin has only his received messages incremented. When we receive the “Statistics” command, we print the output as described above.

 

20
Add=Mark=3=9

Add=Berry=5=5
Add=Clark=4=0
Empty=Berry
Add=Blake=9=3
Add=Michael=3=9
Add=Amy=9=9
Message=Blake=Amy
Message=Michael=Amy
Statistics

Amy reached the capacity!

Users count: 4

Mark - 12

Michael - 13

Blake - 13

Clark - 4

 

12

Add=Bonnie=3=5
Add=Johny=4=4

Empty=All

Add=Bonnie=3=3
Statistics

Users count: 1

Bonnie - 6

Тагове:
0
Fundamentals Module
viktorv19 avatar viktorv19 17 Точки
Best Answer

това е моето решение дава 100/100 надявам се да ти помогне. 

https://pastebin.com/xBeqPqhn

Грешката беше при командата Мessage. При message първо проверяваш дали съществуват и после дали някой стига лимита. А в твоя код дори и дане съществуват пак проверяваше дали някой не е достигнаил лимита. 

Твоят код с тази промяна дава 100/100.

https://pastebin.com/SjRrsyMN

1
01/04/2020 14:58:33
sashotoka avatar sashotoka 2 Точки

Благодаря, колега. 

1
MuP0claB avatar MuP0claB 0 Точки

 Здравейте, случайно някой да има това решение и на JavaScript  ?    

     Благодаря ви предварително  !  smiley

0
Axiomatik avatar Axiomatik 2422 Точки

;-)

function messagesManager(input) {
    const capacity = input.shift();
    let command = input.shift();
    let userList = [];

    while (command !== "Statistics") {
        const arrayCommands = command.split('=');
        const length = arrayCommands.length;

        if (length === 2) {
            const [operation, targetUsername] = arrayCommands;

            if (operation === "Empty") {
                if (targetUsername === "All") {
                    userList = [];
                } else {
                    const targetUser = userList.find((u) => u.username === targetUsername);

                    if (targetUser) {
                        // targetUser.sent = 0;
                        // targetUser.received = 0;
                        userList = userList.filter((u) => u !== targetUser);
                    }
                }
            }
        } else if (length === 3) {
            let [operation, sender, receiver] = arrayCommands;

            if (operation === "Message") {
                const senderTarget = userList.find((u) => u.username === sender);
                const receiverTarget = userList.find((u) => u.username === receiver);

                if (senderTarget && receiverTarget) {
                    if ((senderTarget.sent + 1) + senderTarget.received >= capacity) {
                        console.log(`${sender} reached the capacity!`);
                        userList = userList.filter((u) => u !== senderTarget);
                    } else {
                        senderTarget.sent++;
                    }

                    if ((receiverTarget.received + 1) + receiverTarget.received >= capacity) {
                        console.log(`${receiver} reached the capacity!`);
                        userList = userList.filter((u) => u !== receiverTarget);
                    } else {
                        receiverTarget.received++;
                    }
                }
            }
        } else if (length === 4) {
            let [operation, username, sent, received] = arrayCommands;
            sent = Number(sent);
            received = Number(received);

            if (operation === "Add") {
                if (!userList.some((u) => u.username === username)) {
                    userList.push({
                        username,
                        sent,
                        received,
                    });
                }
            }
        }

        command = input.shift();
    }

    userList
        .sort((a, b) => {
            // if (b.received - a.received === 0) {
            //     return a.username.localeCompare(b.username);
            // } else {
            //   return  b.received - a.received;
            // }

            return b.received - a.received || a.username.localeCompare(b.username);
        });

    console.log(`Users count: ${userList.length}`);
    for (const user of userList) {
        console.log(`${user.username} - ${user.received + user.sent}`);
    }
}

 

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