728x90
문제
Redundancy in this world is pointless.
Let’s get rid of all redundancy.
For example AAABB is redundant.
Why not just use AB?
Given a string, remove all consecutive letters that are the same.
https://www.acmicpc.net/problem/5357
입력
The first line in the data file is an integer that represents the number of data sets to follow.
Each data set is a single string.
The length of the string is less than 100.
Each string only contains uppercase alphabetical letters.
출력
Print the deduped string.
예제
# input
3
ABBBBAACC
AAAAA
ABC
# output
ABAC
A
ABC
문제 풀이
N = int(input())
for _ in range(N):
S = input()
ans = []
for i in range(len(S)):
if not ans or ans[-1] != S[i]:
ans.append(S[i])
print(''.join(ans))
파이썬을 독학하시는 분들에게 도움이 되길 바라며,
혹 더 좋은 방법이 있거나 오류가 있다면 편하게 말씀 부탁드립니다.
728x90