https://www.acmicpc.net/problem/1406
연결리스트 기본 문제였다.
#include <iostream>
#include <list>
using namespace std;
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
string str;
cin >> str;
list<char> l;
for (int i = 0; i < str.length(); i++)
l.push_back(str[i]);
list<char>::iterator it = l.end();
int M;
cin >> M;
for (int i = 0; i < M; i++)
{
char order;
cin >> order;
if (order == 'P')
{
char c;
cin >> c;
l.insert(it, c);
}
else if (order == 'L')
{
if (it != l.begin())
it--;
}
else if (order == 'D')
{
if (it != l.end())
it++;
}
else if (order == 'B')
{
if (it != l.begin())
{
it--;
it = l.erase(it);
}
}
}
for (auto i : l)
cout << i;
}
'PS > BOJ' 카테고리의 다른 글
[백준] 1158. 요세푸스 문제(c++) (0) | 2025.01.26 |
---|---|
[백준] 5397. 키로거(c++) (0) | 2025.01.26 |
[백준] 1919. 애너그램 만들기(c++) (0) | 2025.01.21 |
[백준] 11328. Strfry(c++) (0) | 2025.01.19 |
[백준] 13300. 방 배정(c++) (0) | 2025.01.19 |