반응형
문제
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.
입력
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.
예제 입력 1 복사
3
ABBBBAACC
AAAAA
ABC
예제 출력 1 복사
ABAC
A
ABC
중복 제커하면 된다고 함
입력은 무조건 대문자만 입력되며 길이는 100보다 작다고 한다.
그러면 뭐 for문을 돌려도 1초 이상이 안되기 때문에 괜찮음.
import sys
n = int(sys.stdin.readline())
ps = sys.stdin.readlines()
for p in ps:
tmp = ''
p = p.strip()
for i in p:
if tmp != i:
tmp = i
print(i, end='')
print()
반응형
'알고리즘' 카테고리의 다른 글
[BAEKJOON] 25640 MBTI (0) | 2024.01.21 |
---|---|
[BAEKJOON] 30501 관공... 어찌하여 목만 오셨소... (0) | 2024.01.21 |
[BAEKJOON] 31090 2023은 무엇이 특별할까? (0) | 2024.01.18 |
[BAEKJOON] 25704 출석 이벤트 (0) | 2024.01.17 |
[BAEKJOON] 21964 선린인터넷고등학교 교가 (0) | 2024.01.16 |