728x90
반응형
5397 키로거
문제 풀이
#include <bits/stdc++.h>
#include <ctype.h>
using namespace std;
void fast_io(void)
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
}
int main(void)
{
fast_io();
int t;
cin >> t;
while (t--)
{
string str;
list<char> l;
cin >> str;
list<char>::iterator iter = l.end();
for (int i = 0; i < str.length(); i++)
{
if (isdigit(str[i]) || isalpha(str[i]))
l.insert(iter, str[i]);
else if (str[i] == '<' && iter != l.begin())
iter--;
else if (str[i] == '>' && iter != l.end())
iter++;
else if (str[i] == '-' && iter != l.begin())
iter = l.erase(--iter);
}
for (char c : l)
cout << c;
cout << "\n";
}
}
iter의 전치 후치 연산에따라 값이바뀌고 맨처음에 iter에 end 값으로 초기화 해줘야한다.
728x90
반응형
'자라는 개발자 > 문제풀이' 카테고리의 다른 글
백준 c++ 1205번 등수 구하기 (0) | 2022.01.19 |
---|---|
백준 c++ 7785 회사에 있는 사람 (0) | 2022.01.15 |
백준 c++ 1380 귀걸이 (0) | 2022.01.14 |
백준 c++ 1406번 에디터 (0) | 2022.01.14 |
백준 c++ 1919 애너그램 만들기 (1) | 2022.01.12 |