1048 -- 求某一整数序列的全排列问题

求某一整数序列的全排列问题

Time Limit:1000MS  Memory Limit:65536K
Total Submit:45 Accepted:20

Description

现有一整数序列如:123,请计算出它的全排列。

Input

输入数据有两行组成,第一行为整数序列的长度,第二行为整数序列,序列元素之间以Tab符相隔。

Output

输出数据为整数序列的全排列,每一个排列单独占一行。

Sample Input

3
1 2 3

Sample Output

123
132
213
231
312
321

Source

/*
 * http://183.167.205.82:8081/JudgeOnline/showproblem?problem_id=1048
 * by jtahstu on 2015/2/7 7:00
 * 知识点: 排列生成器     按字典序的下一个排列     next_permutation()
 *                         按字典序的前一个排列     prev_permutation()
 */
#include<iostream>
#include<algorithm>
#include<string>
using namespace std;

int main() {
    int m;
    string s,a;
    cin>>m;
    for(int i=0; i<m; i++) {
        cin>>a;
        s+=a;
    }
    cout<<s<<endl;
    while(next_permutation(s.begin(),s.end()))
        cout<<s<<endl;
    return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值