Phonebook Lookup
Python
Easy
3 views
Problem Description
Read n entries of name and phone. Then one query name is provided. Output the phone if present else output NOT FOUND.
Input Format
First line n. Next n lines: name phone. Last line: queryName.
Output Format
One line answer.
Sample Test Case
Input:
3
Ravi 987
Aman 111
Neha 222
Aman
Official Solution
import sys
lines=sys.stdin.read().splitlines()
if not lines: sys.exit(0)
n=int(lines[0].strip())
d={}
for i in range(1,1+n):
parts=(lines[i] if i<len(lines) else '').split()
if len(parts)<2: continue
d[parts[0]]=parts[1]
q=(lines[1+n] if 1+n<len(lines) else '').strip()
sys.stdout.write(d.get(q,'NOT FOUND'))
Solutions (0)
No solutions submitted yet. Be the first!
No comments yet. Start the discussion!