본문 바로가기
알고리즘

[BAEKJOON] 5357 Dedupe

by mAlfred 2024. 1. 19.
반응형

문제

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()
반응형