3 분 소요

🗒️ 5397번) 키로거

#include <iostream>
#include <list>
using namespace std;

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);

	int N;
	cin >> N;
	while (N--)
	{		
		string input;
		cin >> input;
		
		list<char> pw;
		list<char>::iterator cursor = pw.begin();
		for (char c : input)
		{
			switch (c)
			{
			case '-':
				if (cursor != pw.begin())
					cursor = pw.erase(--cursor);
				break;
			case '<':
				if (cursor != pw.begin())
					cursor--;
				break;
			case '>':
				if (cursor != pw.end())
					cursor++;
				break;
			default:
				pw.insert(cursor, c);
				break;
			}
		}
		
		for (char c : pw)
			cout << c;
		cout << '\n';
	}

	return 0;
}

카테고리:

업데이트:

댓글남기기