Keylogger Gym - 101078I

Problem

As a malicious hacker you are trying to steal your mother’s password, and therefore you have installed a keylogger on her PC (or Mac, so you like). You have a log from your mother typing the password, but unfortunately the password is not directly visible because she used the left and right arrows to change the position of the cursor, and the backspace to delete some characters. Write a program that can decode the password from the given keylog.

Input

The first line of the input contains a single number: the number of test cases to follow.

Each test case has the following format:

• One line with a string L, satisfying 1 ≤ Length(L) ≤ 1, 000, 000, consisting of:

– ’-’ representing backspace: the character directly before the cursor position is deleted, if there is any.

– ’<’ (and ’>’) representing the left  (right) arrow: the cursor is moved 1 character to the left (right), if possible.

– alphanumeric characters, which are part of the password, unless deleted later. We assume ‘insert mode’: if the cursor is not at the end of the line, and you type an alphanumeric character, then all characters after the cursor move one position to the right.

Every decoded password will be of length > 0.

Output

For every test case in the input, the output should contain a single string, on a single line: the decoded password.

Example

Input

2

<<BP<A>>Cd- 

ThIsIsS3Cr3t

Output

BAPC

ThIsIsS3Cr3t

一个左右移动光标,插入和删除的题目

#include<cstdio>
#include<cstring>
//c++的这几个头文件稍微多占点内存,但速度快?
#include<stack>

const int N = 1e6+5;
char st[N], l[N];
void clear( std::stack<char> &q )//新看到的堆栈清空,然而没有用到
{
   std::stack<char> empty;
   std::swap( q, empty );
}
int main()
{
    int n;
    scanf("%d", &n);
    std::stack<char>S;
    while(n--)
    {
        scanf("%s", st);
        int len = strlen(st);
        char *p = l, *q = l;
        for(int i = 0; i < len; i++)
        {
            if(st[i] == '<')
            {
                if(p != l) S.push(*--p);
            }
            else if(st[i] == '>')
            {
                if(p != q)
                {
                    *p++ = S.top();
                    S.pop();
                }
            }
            else if(st[i] == '-')
            {
                if(p!=l)
                {
                    p--; q--;
                }
            }
            else
            {
                while(i < len && st[i] != '<' && st[i] != '>' && st[i] != '-')
                {
                    *p++ = st[i++];
                    q++;
                }
                i--;
            }
        }
        while(!S.empty())
        {
            *p++ = S.top();
            S.pop();
        }
        *p = '\0';
        puts(l);
        clear(S);
    }
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值