Loading...
sasho1232 avatar sasho1232 1 Точки

Programming Fundamentals Mid Exam - 22 October 2023 - задача 02. Friend List Maintenance

Здравейте,

Тази задача ми дава 90/100 и не мога да намеря къде е проблема може ли малко помощ?

 

function friendList(input) {
    const friends = input[0].split(', ');
    const originalNames = [...friends]; // Keep a copy of original names
    const blacklist = new Set();
    const lost = new Set();

    for (let i = 1; i < input.length; i++) {
        const command = input[i].split(' ');

        if (command[0] === 'Blacklist') {
            const name = command[1];
            if (friends.includes(name)) {
                if (!blacklist.has(name)) {
                    if (name != "Lost") {

                        blacklist.add(name);
                        friends[friends.indexOf(name)] = "Blacklisted";
                        console.log(`${name} was blacklisted.`);
                    }
                }
            } else {
                console.log(`${name} was not found.`);
            }
        } else if (command[0] === 'Error') {
            const index = parseInt(command[1], 10);
            if (index >= 0 && index < friends.length) {
                const name = friends[index];
                if (name != "Blacklisted") {
                    if (name != "Lost") {
                        lost.add(name);
                        friends[friends.indexOf(name)] = "Lost";
                        console.log(`${originalNames[index]} was lost due to an error.`);
                    }
                }
            }
        } else if (command[0] === 'Change') {
            const index = parseInt(command[1], 10);
            const newName = command.slice(2).join(' ');
            if (index >= 0 && index < friends.length) {
                if (!(friends[index] == "Blacklisted" || friends[index] == "Lost")) {
                    const currentName = friends[index];
                    friends[index] = newName;
                    console.log(`${currentName} changed his username to ${newName}.`);
                }

            }
        } else if (command[0] === 'Report') {
            console.log(`Blacklisted names: ${blacklist.size}`);
            console.log(`Lost names: ${lost.size}`);
            console.log(`${friends.join(' ')}`);
            break;
        }
    }
}

   

Тагове:
1
Fundamentals Module
helendam avatar helendam 3 Точки

Regular player surveys invite feedback on various aspects of the game, from balance changes to feature preferences, ensuring that player opinions play a pivotal role in shaping the future of 1v1 LOL

0
mladrad avatar mladrad 2 Точки
names_lst = input().split(", ")
black_counter = 0
losted_names = 0
while True:
    command = input().split()
    if command[0] == "Report":
        break
    elif command[0] == "Blacklist":
        name = command[1]
        for i in range(len(names_lst)):
            if names_lst[i] == name:
                print(f"{name} was blacklisted.")
                names_lst[i] = "Blacklisted"
                black_counter += 1
        if black_counter == 0:
            print(f"{name} was not found.")

    elif command[0] == "Error":
        index = command[1]
        if int(index) in range(len(names_lst)):
            if names_lst[int(index)] != "Blacklisted" and names_lst[int(index)] != "Lost":
                print(f"{names_lst[int(index)]} was lost due to an error.")
                names_lst[int(index)] = "Lost"
                losted_names += 1

    elif command[0] == "Change":
        index = command[1]
        new_name = command[2]
        if int(index) in range(len(names_lst)):
            name = names_lst[int(index)]
            names_lst[int(index)] = new_name
            print(f"{name} changed his username to {new_name}.")

print(f"Blacklisted names: {black_counter}")
print(f"Lost names: {losted_names}")
print(' '.join(names_lst))
0
krum_43 avatar krum_43 756 Точки

Може ли линк към условието ?

0
mladrad avatar mladrad 2 Точки

On the first line, you will receive all his friends separated by ", ". On the next lines until the "Report" command, you will receive some commands:

  • "Blacklist {name}":
  • Change the given name to "Blacklisted" and print "{name} was blacklisted.".
  • If there is no such name print: "{name} was not found.".
  • "Error {index}":
  • If the index is valid
  • and the username at the given index is not blacklisted
  • or already lost due to an error, change it to "Lost" and print "{name} was lost due to an error.".
  • Otherwise, ignore the command.
  • "Change {index} {new name}":  
  • If the index is valid, change the current username with the new one and print "{current name} changed his username to {new name}.".
  • Otherwise, ignore the command.

An index is valid when it is non-negative and less than the size of the collection.

After you receive "Report", print on the console the count of blacklisted names, the count of lost names, and the friends' list separated by a single space.

Input / Constraints

  • The first input line will contain the usernames that need to be stored.
  • On the next input lines until "Report", you will receive commands.
  • All given names will be unique.

Output

  • The output should be in the following format:
    • "Blacklisted names: {number of blacklisted names}"
    • "Lost names: {number of lost names}"
    • "{name1} {name2} .. {nameN}"
1
krum_43 avatar krum_43 756 Точки

Задачата все пак е от тех-модула,а не от "Основи на програмирането",а там работният език е английски.

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