Блог пользователя parkershamblin

Автор parkershamblin, история, 4 года назад, По-английски

Hi, this is my first day on Codeforces and I'm currently struggling to get started. Here is the link to the problem I am trying to solve: https://codeforces.com/problemset/problem/71/A

I am not sure why my submission keeps failing on test 1.

lines = input()
lines = lines.splitlines()
n = int(lines[0])

for word in lines[1:n+1]:
    if len(word) > 10:
        abrv = f"{word[0]}{len(word[1:-1])}{word[-1]}"
        print(abrv)
    else:
        print(word)

Does anyone have any ideas?

Thanks, Parker.

  • Проголосовать: нравится
  • -10
  • Проголосовать: не нравится

»
4 года назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

input() takes in one line of input, so lines simply equals "4" for the first test case. Instead of lines.splitlines(), you can do something like lines = [input() for _ in range(n)]. This works because each word is on a separate line.

»
4 года назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

Just a useful hint: you can use custom invocation tab to check how your solution runs on Codeforces server. Sometimes checker error that you can see in the submission page (like in your case wrong output format Unexpected end of file - token expected and Exit code is 1) are not easy to understand or informative enough. Custom invocation gives more details, like File "program.pys3", line 3, in <module> n = int(l[1]) IndexError: list index out of range

»
3 года назад, # |
Rev. 3   Проголосовать: нравится 0 Проголосовать: не нравится
Spoiler

input code:

2 aaaabbbbbbcc a10c word word

what if i want to write the output is:

2 aaaabbbbbbcc word

output: a10c word

Do I need structure here?And how can I write the code?Thanks...

  • »
    »
    3 года назад, # ^ |
    Rev. 4   Проголосовать: нравится 0 Проголосовать: не нравится

    Use markdown and put your code in a spoiler plz bro...

    Like this

    And, actually I didn't understand what you're asking...