Remove All Occurrences
Python
Easy
2 views
Problem Description
Read n integers and value x. Remove all x and output remaining numbers. If nothing left output EMPTY.
Input Format
Line1 n. Line2 n integers. Line3 x.
Output Format
Remaining numbers or EMPTY.
Official Solution
import sys
lines=sys.stdin.read().splitlines()
if len(lines)<3: sys.exit(0)
n=int(lines[0].strip())
a=list(map(int,lines[1].split()[:n]))
x=int(lines[2].strip())
out=[]
for v in a:
if v!=x:
out.append(str(v))
sys.stdout.write('EMPTY' if not out else ' '.join(out))
Solutions (0)
No solutions submitted yet. Be the first!
No comments yet. Start the discussion!