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.
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.
input()
takes in one line of input, solines
simply equals"4"
for the first test case. Instead oflines.splitlines()
, you can do something likelines = [input() for _ in range(n)]
. This works because each word is on a separate line.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:
thats it
i have tried this approach but it stills fails in first test
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
andExit code is 1
) are not easy to understand or informative enough. Custom invocation gives more details, likeFile "program.pys3", line 3, in <module> n = int(l[1]) IndexError: list index out of range
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
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)
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)
probably u forgot to put the next line code
include
using namespace std;
int main(){
}
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...
Use markdown and put your code in a spoiler plz bro...
And, actually I didn't understand what you're asking...
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 - pneumonoultramicroscopicsilicovolcanoconiosis
output: - word - l10n - i18n - p43s Like this. I hope I could explain. Thanks...