반응형
Character recognition software is widely used to digitise printed texts. Thus the texts can be edited, searched and stored on a computer.
When documents (especially pretty old ones written with a typewriter), are digitised character recognition softwares often make mistakes.
Your task is correct the errors in the digitised text. You only have to handle the following mistakes:
S is misinterpreted as 5 O is misinterpreted as 0 I is misinterpreted as 1 The test cases contain numbers only by mistake.
Solution:
def replace(func):
def wrapper(s):
return func(i.isdigit() and {"0":"O","1":"I","5":"S"}[i] or i for i in s)
return wrapper
@replace
def correct(arr):
return ''.join(arr)
Other Solution:
def correct(string):
return string.translate(str.maketrans("501", "SOI"))
def correct(string):
return string.replace('1','I').replace('0','O').replace('5','S')
반응형
'나는 이렇게 학습한다 > Algorithm & SQL' 카테고리의 다른 글
0902. Simple multiplication (0) | 2022.09.02 |
---|---|
0901. Alan Partridge II - Apple Turnover (0) | 2022.09.01 |
0830. Switch it Up! (0) | 2022.08.30 |
0829. Holiday VIII - Duty Free (0) | 2022.08.29 |
0828. Basic Mathematical Operations (0) | 2022.08.28 |