题意:给定一个字符串,然后【会将光标跳转到头,】会将光标调到尾,问最后正确的输入。
思路:直接用list来模拟即可,【的时候就在头插,】就在尾插,也可根据递归顺序解。
code:
#include <bits/stdc++.h>
using namespace std;
char s[100001];
void dfs(int lt,int rt){
int st=rt;
while (st>=lt&&s[st]!='['&&s[st]!=']') st--;
if (s[st]==']') dfs(lt,st-1);
for (int i=st+1;i<=rt;i++) printf("%c",s[i]);
if (s[st]=='[') dfs(lt,st-1);
}
int main()
{
while (~scanf("%s",s)){
dfs(0,strlen(s)-1);
puts("");
}
}

本文探讨了如何通过使用list来模拟输入操作,包括跳转到字符串头部和尾部的功能,详细介绍了算法实现过程和代码解析。
1587

被折叠的 条评论
为什么被折叠?



