728x90
문제
The PLU football coach must submit to the NCAA officials the names of all players that will be competing in NCAA Division II championship game.
Unfortunately his computer keyboard malfunctioned and interchanged the letters ‘i’ and ‘e’.
Your job is to write a program that will read all the names and print the names with the correct spelling.
https://www.acmicpc.net/problem/5358
입력
The file contains a list of names, and each name will be on a separate line.
출력
Print the same list of names with every ‘i’ replaced with an ‘e’, every ‘e’ replaced with an ‘i’, every ‘I’ replaced with an ‘E’, and every ‘E’ replaced with an ‘I’.
예제
# input
Alan Pagi
John Hiesman
Justen Forsitt
Phel Semms
Tem Tibow
Marshawn Lynch
Lion Washengton
# output
Alan Page
John Heisman
Justin Forsett
Phil Simms
Tim Tebow
Marshawn Lynch
Leon Washington
문제 풀이
while True:
try:
S = input()
ans = []
for i in S:
if i == 'i':
ans.append('e')
elif i == 'I':
ans.append('E')
elif i == 'e':
ans.append('i')
elif i == 'E':
ans.append('I')
else:
ans.append(i)
print(''.join(ans))
except:
break
파이썬을 독학하시는 분들에게 도움이 되길 바라며,
혹 더 좋은 방법이 있거나 오류가 있다면 편하게 말씀 부탁드립니다.
728x90