Loading...

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

IvayloGG30 avatar IvayloGG30 -1 Точки

03. Plant Discovery (JS)

Здравейте,

моля за помощ на следната задача:

 

On the first line, you will be given a string containing all of your stops. Until you receive the command "Travel", you will be given some commands to manipulate that initial string. The commands can be:

  • "Add Stop:{index}:{string}":

    • Insert the given string at that index only if the index is valid

  • "Remove Stop:{start_index}:{end_index}":

    • Remove the elements of the string from the starting index to the end index (inclusive) if both indices are valid

  • "Switch:{old_string}:{new_string}":

    • If the old string is in the initial string, replace it with the new one (all occurrences)

Note: After each command, print the current state of the string!

After the "Travel" command, print the following: "Ready for world tour! Planned stops: {string}"

Input / Constraints

  • JavaScript: you will receive a list of strings

  • An index is valid if it is between the first and the last element index (inclusive) (0 ….. Nth) in the sequence.

Output

  • Print the proper output messages in the proper cases as described in the problem description

 

https://judge.softuni.org/Contests/Practice/Index/2518#2

 

Ето и моете решение: https://pastebin.com/sXW7SfqN

дава ми 87/100 като гърми последния 8ми тест.

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

Тагове:
0
Fundamentals Module
Axiomatik avatar Axiomatik 2422 Точки

Demo code =>

function plantDisc(input) {
    let nLines = Number(input.shift());
    let plantObj = {};

    for (let i = 0; i < nLines; i++) {
        let [plant, rarity] = input.shift().split(`<->`)
        plantObj[plant] = {
            plant,
            rarity,
            rating: 0,
            count: 0,
        };
    }

    let currentRow = input.shift();

    while (currentRow !== `Exhibition`) {
        let command = currentRow.split(` - `).join(` `).split(` `);

        if (plantObj.hasOwnProperty(command[1])) {
            switch (command[0]) {
                case `Rate:`:
                    let counter = 1;
                    let plant = command[1];
                    let rating = Number(command[2]);

                    plantObj[plant][`rating`] += rating;
                    plantObj[plant][`count`] += counter;

                    break;
                case `Update:`:
                    let plantT = command[1];
                    let newRarity = Number(command[2]);
                    plantObj[plantT][`rarity`] = newRarity;

                    break;
                case `Reset:`:
                    let resetPlant = command[1];
                    plantObj[resetPlant][`rating`] = 0;
                    plantObj[resetPlant][`count`] = 0;
                    break;
            }
        } else {
            console.log(`error`);
        }

        currentRow = input.shift();
    }

    console.log(`Plants for the exhibition:`);

    for (const key in plantObj) {
        let averageCount = plantObj[key][`rating`] / plantObj[key][`count`] || 0;
        console.log(`- ${key}; Rarity: ${plantObj[key][`rarity`]}; Rating: ${(averageCount).toFixed(2)}`);
    }
}

;-)

0
Kestrel avatar Kestrel 0 Точки

From the problem description, it seems like you need to manipulate a string based on given commands until the "Travel" command is encountered. The commands include adding a stop at a specific index 2 player games, removing a range of elements, and replacing occurrences of a string with a new one.

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