https://www.acmicpc.net/problem/5357
5357번: Dedupe
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.
www.acmicpc.net
1
2
3
4
5
6
7
8
9
10
11
12
13
|
def sol(s):
answer = [s[0]]
for alphabet in s:
if answer[-1] != alphabet:
answer.append(alphabet)
return ''.join(answer)
if __name__ == '__main__':
n = int(input())
for _ in range(n):
s = input()
print(sol(s))
|
cs |
반응형
'python-algorithm' 카테고리의 다른 글
백준 26340 Fold the Paper Nicely (0) | 2022.12.22 |
---|---|
백준 6887 Squares (0) | 2022.12.22 |
백준 26350 Good Coin Denomination (0) | 2022.12.22 |
백준 5300 Fill the Rowboats! (0) | 2022.12.22 |
백준 25756 방어율 무시 계산하기 (0) | 2022.12.22 |
댓글