zoukankan      html  css  js  c++  java
  • UVa11988 Broken Keyboard (a.k.a. Beiju Text)

    模拟题.

    但是可以借这题熟悉一下STL的list用法

    首先, list有push_front 与 pop_front, 但显然, 这俩功能解决不了这个题

    考虑使用迭代器和insert修改器.

    查阅资料, insert插入单个元素时返回值为这个值的位置,

    而且,

    iterator insert( iterator pos, const T& value );

    是在 pos 前插入 value

    了解了这些, 不难写出程序.

     1 #include <cstdio>
     2 #include <cstring>
     3 #include <iostream>
     4 #include <list>
     5 using namespace std;
     6 const int HEAD = 0;
     7 const int TAIL = 1;
     8 
     9 list<char> l;string s;
    10 
    11 int main()
    12 {
    13     //freopen("11988.in", "r", stdin);
    14     ios::sync_with_stdio(false);
    15     char ch; list<char>::iterator it = l.begin();
    16     while(cin>>s)
    17     {
    18         for(int i = 0; i < (int) s.size(); i++)
    19         {
    20             ch = s[i];
    21             if(ch == '[') it = l.begin();
    22             else if(ch == ']') it = l.end();
    23             else it = l.insert(it, ch), it++;
    24         }
    25         for(it = l.begin(); it != l.end(); it++)
    26             cout<<*it;
    27         cout<<endl;
    28         l.clear();
    29     }
    30     
    31     return 0;
    32 }
  • 相关阅读:
    指针和数组的关系
    深入学习数组
    const关键字与指针
    野指针是什么
    指针带来的一些符号的理解
    指针的本质
    内存管理之堆
    内存管理之栈
    元类
    断点调式和面向对象进阶
  • 原文地址:https://www.cnblogs.com/wsmrxc/p/9207281.html
Copyright © 2011-2022 走看看