码迷,mamicode.com
首页 > 其他好文 > 详细

Uva11988

时间:2019-05-19 23:20:13      阅读:125      评论:0      收藏:0      [点我收藏+]

标签:注意   cst   bsp   else   list   ken   key   uva   mes   

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(索引位置,插入对象)

 

Uva11988

标签:注意   cst   bsp   else   list   ken   key   uva   mes   

原文地址:https://www.cnblogs.com/zuiaimiusi/p/10891307.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!