parkershamblin's blog

By parkershamblin, history, 4 years ago, In English

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.

  • Vote: I like it
  • -10
  • Vote: I do not like it

| Write comment?
»
4 years ago, # |
  Vote: I like it 0 Vote: I do not like it

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 years ago, # |
  Vote: I like it 0 Vote: I do not like it

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 years ago, # |
Rev. 3   Vote: I like it 0 Vote: I do not like it
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 years ago, # ^ |
    Rev. 4   Vote: I like it 0 Vote: I do not like it

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

    Like this

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