Python's "indifferent letter" challenge.



  • Unlovable letter

    Anton recently studied the English alphabet and his most indifferent letter is the letter y. If he has a line s, he makes a line s1, removing all the letters "y " from the line s (all the other symbols in the same order). He generated a new line t by connecting s and s1. In other words, t=s+s1.

    You have a line t. Find a line s that Anton used to generate t.

    I had a code:

    def generate(s):
        d = ''
        for i in s:
            if i != 'y':
                d += i
        return d
    a = input()
    d = ''
    for i in range(len(a)):
        d += a[i]
        if a[i+1:] == generate(d):
            print(d)
            exit()
    print(0)
    

    He writes 'There's a time limit on test 11'. How do we streamline the code, he's been working for no more than one second for any line?



  • It's like you made it harder for me, and he could look like,

    text = 'testereser'
    

    res = text[:(len(text)+text.count('t')) // 2]

    print(res)

    Look at the logic:

    The new line contains an old line and an old line without a letter 't'

    If you count how many letters 't' have been deleted (in fact, how many letters 't' are in the new line because they're only in the original line),

    If you don't know what you're talking about, we'll get the length of the double original line,

    a By splitting it into two, we get the length of the reference line.

    The length of the reference line can be distinguished from the outcome.



Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2