하다보니

5397번-키로거 본문

알고리즘 풀이/백준

5397번-키로거

claire 2022. 1. 18. 13:12
#include<bits/stdc++.h>
using namespace std;

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	int n;
	cin >> n;
	while (n--) {
		string s;
		cin >> s;
		list<char> L;
		auto cur = L.end();
		for (auto c : s) {
			if (c == '<') {
				if (cur != L.begin()) cur--;
			}
			else if (c == '>') {
				if (cur != L.end()) cur++;
			}
			else if (c == '-') {
				if (cur != L.begin()) {
					cur--;
					cur = L.erase(cur);
				}
			}
			else {
				L.insert(cur,c);

			}

		}
		for (auto l : L) {
			cout << l;
		}
		cout << "\n";
	}
	
}

'알고리즘 풀이 > 백준' 카테고리의 다른 글

1874번-스택 수열  (0) 2022.01.22
10773번-제로  (0) 2022.01.22
1406번-에디터  (0) 2022.01.17
3273번-두 수의 합  (0) 2022.01.13
1475번-방 번호  (0) 2022.01.13