zoukankan      html  css  js  c++  java
  • [Luogu] 外星密码

    https://www.luogu.org/problemnew/show/P1928

    沙比提

    读清题目

    #include <bits/stdc++.h>
    
    using namespace std;
    const int N = 20010;
    
    int pre[N], hou[N];
    
    string s;
    string ss;
    int main()
    {
        cin >> s;
        if(s.find('[') == -1) {
            cout << s;
            return 0;
        }
        for(int T = 1; T <= 10; T ++){
            
            if(T != 1) s = ss;
            int len = s.length(), last;
            if(s.find('[') == -1) break;
            memset(hou, 0, sizeof(hou));
            bool flag;
            for(int i = 0; i < len; i ++){
                if(s[i] == '[') {last = i; flag = 1;}
                else if(s[i] == ']' && flag) {hou[last] = i; flag = 0;} 
            }
            ss.clear();
            for(int i = 0; i < len; i ++){
                if(!hou[i]) {ss += s[i]; continue ;}
                int tot = 0, j;
                j = i + 1;
                while(s[j] >= '0' && s[j] <= '9'){
                    tot = tot * 10 + s[j] - '0';
                    j ++;
                }
                string s1;
                while(s[j] != ']') s1 += s[j ++];
                for(int k = 1; k <= tot; k ++) ss += s1;
                i = hou[i];
            }
        }
        cout << ss;
        
        return 0;
    }
  • 相关阅读:
    2-7
    2-6
    2-5
    2-4
    2-3
    2-1
    2-2
    1-1
    5-7
    第六章例6-1
  • 原文地址:https://www.cnblogs.com/shandongs1/p/8214679.html
Copyright © 2011-2022 走看看