woj 1478 Key Logger(list)

模拟题:

http://acm.whu.edu.cn/land/problem/detail?problem_id=1478

#include<stdio.h>
#include<string>
#include<list>
#include<iostream>
using namespace std;
string s;
string ::iterator its;
list<char>l;
list<char>::iterator itl;
int main()
{
    int n;
    scanf("%d",&n);
    for(int i=0;i<n;i++)
    {
        s.clear();
        l.clear();
        //scanf("%s",s);
        cin>>s;
        itl=l.begin();
        for(int j=0;j<s.size();j++)
        {
            if(s[j]=='<')
            {
                if(itl!=l.begin())itl--;
            }
            else if(s[j]=='>')
            {
                if(itl!=l.end())itl++;
            }
            else if(s[j]=='-')
            {
                if(itl!=l.begin())
                {
                    itl--;
                    itl=l.erase(itl);
                }
            }
            else
            {
                l.insert(itl,s[j]);
            }
        }
        printf("Case %d: ",i+1);
        for(itl=l.begin();itl!=l.end();itl++)
        printf("%c",*itl);
        printf("\n");
    }
    return 0;
}

@@若不string和list定义放在main里面就会MLE


原文地址:https://www.cnblogs.com/XDJjy/p/3039006.html