Batch Sum (T Testcases)
Python
Easy
4 views
Problem Description
First number t is provided. For each testcase, two integers a and b are provided. Output a+b for each testcase.
Input Format
First integer t. Then t lines: a b.
Output Format
t lines sums.
Sample Test Case
Input:
4
10 5
1 2
-3 7
100 0
Official Solution
import sys
p=sys.stdin.read().strip().split()
if not p:
sys.exit(0)
it=iter(p)
t=int(next(it))
out=[]
for _ in range(t):
try:
a=int(next(it)); b=int(next(it))
out.append(str(a+b))
except Exception:
out.append('0')
sys.stdout.write('\
'.join(out))
Solutions (0)
No solutions submitted yet. Be the first!
No comments yet. Start the discussion!