jezyki-formalne-i-zlozonosc.../TaskC21_TODO/solution.py

26 lines
732 B
Python

# HORSE HEAD -> 46773 4323
import re
import sys
pattern = r'^[A-Z][A-Z][A-Z][A-Z][A-Z] [A-Z][A-Z][A-Z][A-Z]$'
def get_number(c):
result = re.sub(r'[ABC]', '2', c)
result = re.sub(r'[DEF]', '3', result)
result = re.sub(r'[GHI]', '4', result)
result = re.sub(r'[JKL]', '5', result)
result = re.sub(r'[MNO]', '6', result)
result = re.sub(r'[PQRS]', '7', result)
result = re.sub(r'[TUV]', '8', result)
result = re.sub(r'[WXYZ]', '9', result)
return result
for line in sys.stdin:
line = line.strip('\n')
if not re.match(pattern, line):
print('no')
continue
num = ''.join(get_number(c) for c in line.replace(' ', ''))
print('yes' if re.match(r'^467734323$', num) else 'no')