[BOJ] 5397번 : 키로거
2024. 8. 5. 20:58ㆍAlgorithm
1. problem :
https://www.acmicpc.net/problem/5397
2. solution 1 :
#include <bits/stdc++.h>
using namespace std;
int main(void) {
ios::sync_with_stdio(0);
cin.tie(0);
int testCase;
cin >> testCase;
while (testCase--) {
list<char> L = {};
auto cursor = L.begin();
string init;
cin >> init;
for (auto c : init) {
if (c == '<') {
if (cursor != L.begin()) cursor--;
}
else if (c == '>') {
if (cursor != L.end()) cursor++;
}
else if (c == '-') {
if (cursor != L.begin()) {
cursor--;
cursor = L.erase(cursor);
}
}
else {
L.insert(cursor, c);
}
}
for (auto c : L) cout << c;
cout << '\n';
}
return 0;
}
## barkingdog님의 source code를 보고 따라 했다.
<출처> https://github.com/encrypted-def/basic-algo-lecture/blob/master/0x04/solutions/5397.cpp
'Algorithm' 카테고리의 다른 글
[BOJ]10773번 : 제로 (0) | 2024.08.06 |
---|---|
[BOJ] 1158번 : 요세푸스 (0) | 2024.08.06 |
[BOJ] 1406: 에디터 (0) | 2024.08.05 |
[Boj]1919: 애너그램 만들기 (0) | 2024.08.04 |
[Boj]11326:Strfry (0) | 2024.08.04 |