Batch Division With Line Errors
Python
Hard
2 views
Problem Description
First line q. Next q lines have a b. For each line output a//b. If b is 0 or parsing fails, output ERROR for that line.
Input Format
First line q. Next q lines: a b.
Output Format
q lines results.
Sample Test Case
Input:
4
10 2
5 0
x 3
9 3
Official Solution
import sys
lines=sys.stdin.read().splitlines()
if not lines: sys.exit(0)
try:
q=int(lines[0].strip())
except Exception:
sys.stdout.write('')
raise SystemExit
out=[]
for i in range(1,1+q):
parts=(lines[i] if i<len(lines) else '').split()
if len(parts)<2:
out.append('ERROR')
continue
try:
a=int(parts[0]); b=int(parts[1])
out.append('ERROR' if b==0 else str(a//b))
except Exception:
out.append('ERROR')
sys.stdout.write('\
'.join(out))
Solutions (0)
No solutions submitted yet. Be the first!
No comments yet. Start the discussion!