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;
}
'Baekjoon > C++' 카테고리의 다른 글
[C++][BOJ/백준] 4766 일반 화학 실험 (0) | 2024.02.25 |
---|---|
[C++][BOJ/백준] 11023 더하기 3 (0) | 2024.02.20 |
[C++][BOJ/백준] 23804 골뱅이 찍기 - ㄷ (0) | 2024.02.14 |
[C++][BOJ/백준] 5613 계산기 프로그램 (0) | 2024.02.13 |
[C++][BOJ/백준] 5586 JOI와 IOI (0) | 2024.02.12 |