[Python] Troublesome Keys from CCC 2024 J4: Cannot distinguish between quiet and silly key

Discussão em 'Python' iniciado por Stack, Fevereiro 19, 2025.

  1. Stack

    Stack Membro Participativo

    My code for the CCC 2024 J4 problem Troublesome Keys does not seem to be working :(

    A summary of the problem: a string of letters is typed, which creates a string with a quiet key (letter not displayed) and a silly key (swapped letter). For example, typing 'forloops' results in 'fxrlxxp' if 'o' is the silly key swapped with 'x', and 's' is the quiet key. Given these two strings, you have to identify the silly key's original and swapped letter, as well as the quiet key's letter.

    My current code has trouble distinguishing between the quiet and silly keys if they occur with the same frequency, I think. Here:

    typed = input()
    displayed = input()
    quiet = '-'

    if len(typed) == len(displayed):
    for i in range(len(typed)):
    if typed != displayed:
    silly = displayed
    orig = typed
    break

    elif len(typed) != len(displayed):
    diff = abs(len(typed) - len(displayed))
    for i, letter in enumerate(typed):
    if typed.count(letter) == diff and letter not in displayed:
    quiet = letter
    orig_wo_quiet = typed.replace(quiet, '')
    quiet_i = i
    break

    for i in range(len(displayed)):

    if orig_wo_quiet != displayed:
    silly = displayed
    orig = orig_wo_quiet
    break

    print(orig, silly)
    print(quiet)


    I would greatly appreciate any help! Thanks!!

    Continue reading...

Compartilhe esta Página