Loading...

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

Vladicha avatar Vladicha 3 Точки

Password reset 50/100

https://judge.softuni.org/Contests/Practice/Index/2303#0

https://pastebin.com/NEwzmYCG

Здравейте, имам проблем със следната задача. Опитвам се да я счупя, но така и не си намирам грешката. Ако може някой да помогне : )

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

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

;-)

100% code =>

function password(inp) {
    let count = 0;
    let sum = '';
    let sentencetoworkat = inp.shift();


    while (inp[0] != "Done") {
        let [name, p1, p2] = inp.shift().split(' ');
        // let name = tokens[0]
        // let p1 = tokens[1]
        // let p2 = tokens[2]

        switch (name) {
            case "TakeOdd":
                for (let el of sentencetoworkat) {
                    if (count !== 0) {
                        if (count % 2 !== 0 || count == 1) {
                            sum += el;
                        }
                    }

                    count++;
                }
                count = 0;
                sentencetoworkat = sum;
                sum = '';
                console.log(sentencetoworkat);

                break;
            case "Cut":
                let index = Number(p1);
                let length = Number(p2);
                let substring = sentencetoworkat.substring(index, index + length);
                sentencetoworkat = sentencetoworkat.replace(substring, '');
                console.log(sentencetoworkat);

                break;
            case "Substitute":
                if (sentencetoworkat.includes(p1)) {
                    let replaced = sentencetoworkat.split(p1).join(p2)
                    sentencetoworkat = replaced;

                    console.log(sentencetoworkat);
                } else { console.log("Nothing to replace!") }

                break;
        }
    }

    console.log(`Your password is: ${sentencetoworkat}`);
}

 

1
Vladicha avatar Vladicha 3 Точки

Благодаря! Обаче е доста по различен е кода и все още не мога да си намеря грешката...

0
Axiomatik avatar Axiomatik 2422 Точки

;-)

function passwordReset(input) {
    // First, you will receive a string, and afterward, until the command "Done" is given, 
    // you will be receiving strings with commands split by a single space.
    let password = input.shift();

    // The destructuring assignment syntax is a JavaScript expression that makes it possible 
    // to unpack values from arrays, or properties from objects, into distinct variables.
    // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Destructuring_assignment
    let [line0, line1, line2] = input[0].split(' ');
    let finalPass = password;


    while (line0 !== 'Done') {
        // if (line[0] === 'Done') {
        //     break;
        // }

        if (line0 === 'TakeOdd') {
            // TakeOdd => Takes only the characters at odd indices and concatenates them to obtain 
            // the new raw password and then prints it.
            let newPass = '';

            for (let i = 1; i < finalPass.length; i = i + 2) {
                newPass += finalPass[i];
                // finalPass = finalPass + password[i];
            }
            finalPass = newPass;
            console.log(finalPass);
        } else if (line0 === 'Cut') {
            // Cut => Gets the substring with the given length starting from the given index from the password 
            // and removes its first occurrence, then prints the password on the console.
            let substring = finalPass.substr(Number(line1), Number(line2));
            finalPass = finalPass.replace(substring, '');
            console.log(finalPass);

            // let oldFinalPass = finalPass.substring(0, Number(line[1]));
            // finalPass = oldFinalPass + finalPass.substring((Number(line[1]) + Number(line[2])), finalPass.length);
            // } else if (line[0] === 'Substitute' && finalPass.includes(line[1])) {
        } else if (line0 === 'Substitute') {
            // Substitute => If the raw password contains the given substring, replaces all of its occurrences 
            // with the substitute text given and prints the result.
            if (finalPass.includes(line1) === false) {
                // If it doesn't, prints "Nothing to replace!".
                console.log('Nothing to replace!');
            } else {
                while (finalPass.includes(line1)) {
                    finalPass = finalPass.replace(line1, line2);
                }
                
                console.log(finalPass);
            }
            
            // finalPass = finalPass.split(line[1]);
            // finalPass = finalPass.join(line[2]);
        }
        // else {
        //     console.log('Nothing to replace!');
        // }

        input.shift();
        [line0, line1, line2] = input[0].split(' ');


        // line = input.shift().split(' ')
        // if (line[0] != 'Done') {
        // } else {
        //     break;
        // }
    }

    console.log(`Your password is: ${finalPass}`);
}

 

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