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("\n");
37    }
38     return 0;
39 }

注意点:

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

 

转载于:https://www.cnblogs.com/zuiaimiusi/p/10891307.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值