parkershamblin's blog

By parkershamblin, history, 2 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?
»
2 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.

»
2 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

»
2 years ago, # |
  Vote: I like it 0 Vote: I do not like it

w = str(input()) def Division(x): if len(x)<= 10: print(x) else: first = x[0] last = x[-1] lenght = len(x[1:-1]) print(f"{first}{lenght}{last}")

Division(w)

Here is my code to but am getting wrong answers but in my test cases in terminal it works fine

  • »
    »
    2 months ago, # ^ |
    Rev. 2   Vote: I like it 0 Vote: I do not like it

    nevermind i just fixed the code. Turns out the number is actually the amount of words you want to input. My dumbass just didn't understand the queston properly. The questions themselves are harder to understand than actually solving it smh

»
21 month(s) 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...

  • »
    »
    21 month(s) 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...