✏️ 𝗔𝗹𝗴𝗼𝗿𝗶𝘁𝗵𝗺/SW Expert Academy
[SW10912] 외로운 문자
yeomss
2022. 5. 29. 10:18
SW Expert Academy- 외로운 문자
문제 링크
SW Expert Academy
SW 프로그래밍 역량 강화에 도움이 되는 다양한 학습 컨텐츠를 확인하세요!
swexpertacademy.com
문제 입력
6
xxyyzz
yc
aaaab
bca
ppzqq
qnwerrewmq
#1 Good
#2 cy
#3 b
#4 abc
#5 z
#6 mn
문제 풀이
import sys
from copy import deepcopy
sys.stdin = open('input.txt', 'rt')
T = int(input())
for t in range(T):
s = input()
ans = list(s)
for x in s:
if ans.count(x) >= 2:
ans.pop(ans.index(x))
ans.pop(ans.index(x))
if not len(ans):
print(f"#{t + 1} Good")
else:
print(f"#{t + 1}", ''.join(sorted(ans)))
만약 2개 이상이 있으면 인덱스를 찾아 2번 pop 합니다.
이러면 같은 문자를 짝으로 삭제가 가능합니다.
# SW Expert 외로운문자 python 파이썬
728x90