zoukankan      html  css  js  c++  java
  • UVA 11988(list, deque)

    题目链接

    题目大意

      你的键盘出现了奇妙的故障,所有键都会正常的工作,但是键盘上的Home以及End键有时候会莫名其妙的自己按下。但是盲打很熟练的你一般习惯关闭显示器打字,因为这样很酷。现在你正在打一段文本,假设你已经知道这段文本以及Home和End键会什么时候出现故障自行按下。请你编写一个程序,求出你最后打出的文本。

    解题思路

      参考dalao的blog,发现用list模拟真的很方便,比我用deque好写多了。

    list代码

    int main() { 
        IOS; string s;
        while(cin >> s) {
            list<char> l;
            auto it = l.begin();
            for (auto ch : s) {
                if (ch == '[') it = l.begin();
                else if (ch == ']') it = l.end();
                else {
                    it = l.insert(it, ch), ++it;
                }
            }
            for (auto ch : l) cout << ch;
            cout << endl; 
        }
    	return 0;
    } 
    

    附上我丑陋的deque代码

    int main() {
        string str;
        while(cin >> str) {
            deque<string> dq; string s;
            int flag = -1, flag2 = 0;
            for (int i = 0; str[i]; ++i) {
                if (str[i]=='[') flag = 1;
                else if (str[i]==']') flag = 0;
                if (flag!=-1) {
                    if (flag2) dq.push_front(s);
                    else dq.push_back(s); 
                    flag2 = flag; flag = -1;
                    s.clear();
                }
                if (str[i]!='['&&str[i]!=']') s += str[i];
            }
            if (!s.empty()) {
                if (flag2) dq.push_front(s);
                else dq.push_back(s); 
                s.clear();
            }
            while(!dq.empty()) cout << dq.front(), dq.pop_front();
            putchar(endl);
            str.clear();
        }
        return 0;  
    }
    
  • 相关阅读:
    oracle RAC 更换IP
    12C oracle 12.1.0.2版本打补丁
    node name配置错误,导致grid日志在报警
    input_subsys 输入子系统框架分析
    www.bing.com
    getopt函数使用说明
    FreeType 矢量字体 测试移植(1)
    字符的编码方式
    在开发板上显示字符和中文
    块设备驱动程序的框架
  • 原文地址:https://www.cnblogs.com/shuitiangong/p/13675773.html
Copyright © 2011-2022 走看看