본문 바로가기

Baekjoon/C++

[C++][BOJ/백준] 5357 Dedupe

 

 

Baekjoon Online Judge

 

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

 

 

[문제]

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.

 

 


 

[코드]

#include <iostream>
using namespace std;

int main()
{
    int n;
    string s;

    cin >> n;

    while (n--)
    {
        char tmp = ' ';

        cin >> s;

        for (int i = 0; i < s.length(); i++)
        {
            if (tmp != s[i])
            {
                cout << s[i];
                tmp = s[i];
            }
        }

        cout << '\n';
    }

    return 0;
}