POJ1731 (Orders)做题笔记

·· / ·– ·· ·-·· ·-·· / ·–· · ·-· ··· ·· ··· - / ··- -· - ·· ·-·· / ·· / ·– ·· -·
题目链接:http://poj.org/problem?id=1731
STL中的next_permutation,作用是生成当前序列的字典序较大的下一个序列,如果能生成则返回true,否则返回false。
还有一个反向的函数prev_permutation。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <string>
int main() {
std::ios::sync_with_stdio(false);
std::string str;
std::cin >> str;
sort(str.begin(),str.end());
std::cout << str << std::endl;
while(next_permutation(str.begin(),str.end())) {
std::cout << str << std::endl;
}
return 0;
}