zoukankan      html  css  js  c++  java
  • UVA 11988 Broken Keyboard (a.k.a. Beiju Text) (链表,模拟)

    使用list来模拟就行了,如果熟悉list,那么这道题真是分分钟秒掉。。。

    list是双向循环链表,插入和删除操作非常快,缺点是不能像数组一样随机按下标读取。

    一下是wiki上说明的相关函数:http://zh.wikipedia.org/wiki/List_(STL)

    • Iterators:
      • list.begin() 回传指向第一个元素的 Iterator。
      • list.end() 回传指向最末元素的下一个位置的 Iterator。
      • list.rbegin() 回传指向最末个元素的反向 Iterator。
      • list.rend() 回传指向第一个元素的前一个位置的反向 Iterator。
    • Capacity/Size:
      • list.empty() 若list内部为空,则回传true值。
      • list.size() 回传list内实际的元素个数。
      • list.resize() 重新分派list的长度。
    • Element Access
      • list.front() 存取第一个元素。
      • list.back() 存取最末个元素。
    • Modify methods
      • list.push_front() 增加一个新的元素在 list 的前端。
      • list.pop_front() 删除 list 的第一个元素。
      • list.push_back() 增加一个新的元素在 list 的尾端。
      • list.pop_back() 删除 list 的最末个元素。
    #include<iostream>
    #include<cstdio>
    #include<cstdlib>
    #include<cstring>
    #include<string>
    #include<cmath>
    #include<map>
    #include<set>
    #include<vector>
    #include<list>
    #include<deque>
    #include<algorithm>
    #include<stack>
    #include<queue>
    #include<cctype>
    #include<sstream>
    using namespace std;
    #define pii pair<int,int>
    #define LL long long int
    const double eps=1e-10;
    const int INF=1000000000;
    
    const int maxn=100000+10;
    char s[maxn];
    list<char>l;
    
    int main()
    {
        //freopen("in1.txt","r",stdin);
        //freopen("out.txt","w",stdout);
        while(scanf("%s",s)==1)
        {
            int len=strlen(s);
            list<char>::iterator it=l.begin();
            for(int i=0;i<len;i++)
            {
                if(s[i]=='[')
                {
                    it=l.begin();
                }
                else if(s[i]==']')
                {
                    it=l.end();
                }
                else
                {
                    l.insert(it,s[i]);
                }
            }
            for(it=l.begin();it!=l.end();it++)
            {
                putchar(*it);
            }
            printf("
    ");
            l.clear();
        }
        return 0;
    }
    View Code
  • 相关阅读:
    Web前端之jQuery 的10大操作技巧
    Python开发者须知 —— Bottle框架常见的几个坑
    string、const char*、 char* 、char[]相互转换
    SLAM中的变换(旋转与位移)表示方法
    SLAM
    二叉搜索树(BST)
    Linux下OSG的编译和安装以及遇到的问题
    CMake--Set用法
    CMake--List用法
    php面向对象面试题
  • 原文地址:https://www.cnblogs.com/zywscq/p/4281670.html
Copyright © 2011-2022 走看看