Trim Length For Each Line
Python
Easy
5 views
Problem Description
Read t lines. For each line, remove leading and trailing spaces and output the length of the remaining text.
Input Format
First line t. Next t lines strings.
Output Format
t lines lengths.
Constraints
Total characters
Official Solution
import sys
lines=sys.stdin.read().splitlines()
if not lines:
sys.exit(0)
try:
t=int(lines[0].strip())
except Exception:
t=0
out=[]
idx=1
for _ in range(t):
s=lines[idx] if idx<len(lines) else ''
idx+=1
out.append(str(len(s.strip())))
sys.stdout.write('\
'.join(out))
Solutions (0)
No solutions submitted yet. Be the first!
No comments yet. Start the discussion!