백준 5397번) 키로거

하우르·2021년 3월 24일
0
post-custom-banner
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.ListIterator;

public class Main {
	public static void main(String[] args) throws NumberFormatException, IOException {
		BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
		int N = Integer.parseInt(reader.readLine());
		LinkedList<Character> list;
		String s = new String();
		ArrayList<String> answer = new ArrayList<String>();
		StringBuilder builder = new StringBuilder();
		ListIterator<Character> iterator;
		for(int i=0; i<N; i++)
		{
			list = new LinkedList<Character>();
			s = reader.readLine();
			iterator= list.listIterator();
			for (int j = 0; j < s.length(); ++j) {

				char cmd = s.charAt(j);
				if((cmd >= 'a' && cmd <= 'z') || (cmd >= 'A' && cmd <= 'Z') || (cmd >= '0' && cmd <= '9'))
					iterator.add(cmd);
				switch (cmd) {
				case '<':
					if (iterator.hasPrevious())
						iterator.previous();
					break;
				case '>':
					if (iterator.hasNext())
						iterator.next();
					break;
				case '-':
					if (iterator.hasPrevious()) {
						iterator.previous();
						iterator.remove();
					}
					break;
				}
			}
			builder = new StringBuilder();
			for (char c : list)
				builder.append(c);
			answer.add(builder.toString());

		}


		for (String c : answer)
			System.out.println(c.toString());

	}
}
profile
주니어 개발자
post-custom-banner

0개의 댓글