### parkershamblin's blog

By parkershamblin, history, 10 months ago,

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

 » 10 months ago, # |   0 I forgot to mention that my code produces the correct result for the sample input in vscode but as previously stated returns an error when I submit it on codeforces.
 » 10 months ago, # |   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.
 » 10 months ago, # | ← Rev. 2 →   0 Simply,you can take an input of no. of test cases ex:-"4" and then make a for loop (for the number of test cases) and then accept each word inputted by the user. eg: a=int(input()) for i in range(0,a): x=input() //input a word "" calculate the ans"" print(*the answer) thats it
•  » » 8 months ago, # ^ |   0 i have tried this approach but it stills fails in first test
 » 10 months ago, # |   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 n = int(l[1]) IndexError: list index out of range
 » 8 months ago, # |   0 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
 » 8 months ago, # |   0 Most of the time the problem is the execution time in codeforces i am also new and have solved the easy problems so here is my solution: for i in range(int(input())): s=input() print(s[0]+str(len(s)-2)+s[len(s)-1] if (len(s)>10) else s)
»
4 months ago, # |
0

# Way to long word problem

total_words=int(input()) for i in range(0,total_words): str1=input() if len(str1)> 10: print(f"{str1[0]}{int(len(str1) — 2)}{str1[len(str1)-1]}") else: print(str1)

 » 2 months ago, # |   0 probably u forgot to put the next line code
»
7 weeks ago, # |
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...

•  » » 7 weeks ago, # ^ | ← Rev. 4 →   0 Use markdown and put your code in a spoiler plz bro... Like this#include using namespace std; int main(){ int n; cin >> n; while( n-- ){ string s; cin >> s; int l = s.length(); if( l > 10 ) cout << s[0] << l-2 << s[l-1] << endl; else cout << s << endl; } return 0; And, actually I didn't understand what you're asking...
•  » » » 7 weeks ago, # ^ |   0 Sorry about the spoiler. I'm new here. I didn't know that. And my question is, when I run code on compiler, it gives me first strings output. For example my input is (word) and it printing the next line (word). I don't want the output is after every string. I want it after all string input, like: - 4 - word - localization - internationalization - pneumonoultramicroscopicsilicovolcanoconiosisoutput: - word - l10n - i18n - p43s Like this. I hope I could explain. Thanks...