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;
}
}
}
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))