• 牛客周赛19 D 神器大师泰兹瑞与威穆 (模拟)


    模拟vim (雾
    用两个栈s1, s2去模拟,s2的top位置就是光标。这样无论删除还是添加都很方便

    #include<iostream>
    #include<cstdio>
    #include<cstring>
    #include<algorithm>
    #include<cmath>
    #include<map>
    #include<stack>
    #include<queue>
    #include<vector>
    #include<string>
    #include<fstream>
    // #include<unordered_map>
    using namespace std;
    #define rep(i, a, n) for(int i = a; i <= n; ++ i)
    #define per(i, a, n) for(int i = n; i >= a; -- i) 
    #define px first
    #define py second  
    typedef long long ll;
    typedef pair<int,int>PII;
    const int N = 2e5 + 10;
    const ll mod = 998244353;
    const double Pi = acos(- 1.0);
    const int INF = 0x3f3f3f3f;
    const int G = 3, Gi = 332748118;
    ll qpow(ll a, ll b) { ll res = 1; while(b){ if(b & 1) res = (res * a) % mod; a = (a * a) % mod; b >>= 1;} return res; }
    ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
    //
    
    stack<char> s1,s2;
    char t[N];
    int num[50];
    
    int main()
    {
        scanf("%s",t + 1);
        int sn = strlen(t + 1);
        for(int i = sn; i >= 1; -- i){
            s2.push(t[i]);
            num[t[i] - 'a'] ++;
        }
        scanf("%s",t + 1);
        int tn = strlen(t + 1);    
        int l = 1, flag = 0;
        for(int i = 1; i <= tn; ++ i){
            char op = t[i]; 
            if(flag){   //Insert Mode
                if(op == 'e'){
                    flag = 0;
                    continue;
                }
                s1.push(op);
            }
            else{       // Normal Mode
                if(op == 'i'){
                    flag = 1;
                    continue;
                }
                else if(op == 'f' && s2.size()){
                    op = t[++ i];
                    if(!num[op - 'a'] || (num[op - 'a'] == 1 && s2.top() == op)) continue;
                    num[s2.top() - 'a'] --;
                    s1.push(s2.top()); s2.pop();
                    while(s2.size() && s2.top() != op){
                        num[s2.top() - 'a'] --;
                        s1.push(s2.top()); s2.pop();                    
                    }
                }
                else if(op == 'x' && s2.size()){
                    num[s2.top() - 'a'] -- , s2.pop();
                }
                else if(op == 'h' && s1.size()){
                    num[s1.top() - 'a'] ++;
                    s2.push(s1.top()), s1.pop();
                }
                else if(op == 'l' && s2.size()){
                    num[s2.top() - 'a'] --;
                    s1.push(s2.top()), s2.pop();
                }
            }
        }
        while(s1.size()){
            s2.push(s1.top()); s1.pop();
        }
        while(s2.size()){
            printf("%c",s2.top()); s2.pop();
        }
        printf("
    ");
        return 0;
    }
    
  • 相关阅读:
    ubuntu12.04 安装eclipse
    loj 1429(可相交的最小路径覆盖)
    loj 1406(状态压缩)
    mysql数据库表插入单条数据/批量插入数据
    window7安装MongoDB详细步骤
    django中的setting全局变量的导入
    django.core.exceptions.ImproperlyConfigured: Requested setting DEFAULT_INDEX_TABLESPACE的解决办法(转)
    DjangoDRF序列化组件使用
    python并发编程知识点总结
    协程+IO切换实现并发
  • 原文地址:https://www.cnblogs.com/A-sc/p/13491031.html
Copyright © 2020-2023  润新知