Parallel Swaps
Python
Medium
5 views
Problem Description
Read n pairs (a,b). For each pair swap them and output. This is to practice variable assignment quickly.
Input Format
First line n. Next n lines: a b.
Output Format
n lines swapped.
Official Solution
import sys
data=sys.stdin.read().strip().split()
if not data:
sys.exit(0)
it=iter(data)
n=int(next(it))
out=[]
for _ in range(n):
a=int(next(it)); b=int(next(it))
a,b=b,a
out.append(f'{a} {b}')
sys.stdout.write(chr(10).join(out))
Solutions (0)
No solutions submitted yet. Be the first!
No comments yet. Start the discussion!