Uva11988

Broken Keyboard (a.k.a. Beiju Text) UVA - 11988

用stl的链表做的,模拟链表的方法暂时没学会,先给自己挖个坑,以后来填。

 1 #include <cstdio>
 2 #include <iostream>
 3 #include <queue>
 4 #include <vector>
 5 #include<string.h>
 6 #include<map>
 7 #include<bits/stdc++.h>
 8 #define LL long long
 9 using namespace std;
10 #define maxn 100005
11 int last,cur,next[maxn];
12 char str[maxn],ch;
13 int main()
14 {
15    while(~scanf("%s",str))
16    {
17        list<char> s;
18        list<char>::iterator it;
19        it=s.begin();
20        int len=strlen(str);
21        for(int i=0;i<len;i++)
22        {
23            ch=str[i];
24            if(ch=='[')
25             it=s.begin();
26            else if(ch==']')
27             it=s.end();
28            else
29            {
30                it=s.insert(it,ch);
31                it++;
32            }
33        }
34        for(it=s.begin();it!=s.end();it++)
35            printf("%c",*it);
36        printf("
");
37    }
38     return 0;
39 }

注意点:

1.一定要及时更新it的位置it=s.insert(it,ch);,如果写成s.insert(it,ch);,it的位置不明确会出错。insert(索引位置,插入对象)