题解 | #火车进站#

火车进站

https://www.nowcoder.com/practice/97ba57c35e9f4749826dc3befaeae109

//https://www.nowcoder.com/practice/97ba57c35e9f4749826dc3befaeae109?tpId=37&rp=1&ru=%2Fexam%2Foj%2Fta&qru=%2Fexam%2Foj%2Fta&sourceUrl=%2Fexam%2Foj%2Fta%3Fpage%3D1%26pageSize%3D50%26search%3D50%26tpId%3D37%26type%3D37&difficulty=&judgeStatus=&tags=&title=%E7%81%AB%E8%BD%A6&gioEnter=menu

#include <iostream>
#include <vector>
#include <algorithm>
#include <stack>

using namespace std;

void dfs(vector<char> in, int index, stack<char> &st, string &out, vector<string> &ans){
    if(index==in.size()&&st.empty()){
        ans.push_back(out);
        return;
    }

    if(index<in.size()){
        st.push(in[index]);
        dfs(in, index+1, st, out, ans);
        st.pop();
    }

    if(!st.empty()){
        out.push_back(st.top());
        st.pop();
        dfs(in, index, st, out, ans);
        st.push(out.back());
        out.pop_back();
    }

}

int main() {
    int n = 0;

    while(cin >> n){
        vector<char> in(n);

        for(int i = 0;i<n;i++){
            cin >> in[i];

            //cout << in[i];

        }

        stack<char> st;
        string out;
        vector<string> ans;

        dfs(in, 0, st, out, ans);

        sort(ans.begin(), ans.end());

        for(auto cstr:ans){
            for(auto cc:cstr)
                cout << cc << " ";
            cout << endl;
        }

    }

}

全部评论

相关推荐

05-12 11:09
已编辑
门头沟学院 后端
已注销:没必要放这么多专业技能的描述。这些应该是默认已会的,写这么多行感觉在凑内容。项目这块感觉再包装包装吧,换个名字,虽然大家的项目基本都是网上套壳的,但是你这也太明显了。放一个业务项目,再放一个技术项目。技术项目,例如中间件的一些扩展和尝试。
简历中的项目经历要怎么写
点赞 评论 收藏
分享
Java抽象带篮子:简历怎么写可以看看我发的帖子,你的第一个是实习经历吗?那怎么写的是你的第一个练手项目呢?简历写的怎么样直接投小厂面试一下就知道了
没有实习经历,还有机会进...
点赞 评论 收藏
分享
找个工作&nbsp;学历是要卡的&nbsp;要求是高的&nbsp;技能不足是真的&nbsp;实习经验是0的&nbsp;简历无处可写是事实的&nbsp;钱不好赚是真的&nbsp;想躺平又不敢躺&nbsp;也不甘心躺&nbsp;怕自己的灵感和才华被掩埋甚至从未被自己发现&nbsp;又质疑自己是否真正有才华
码农索隆:你现在啊,你心里都明白咋回事,但是你没办法改变现状,一想到未来,你又没有信心狠下心来在当下努力。 得走出这种状态,不能一直困在那里面,哪不行就去提升哪,你一动不动那指定改变不了未来,动起来,积少成多才能越来越好
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务