#include <iostream> #include <algorithm> using namespace std; int main() { int i; int source[30]; int size; cin >> size; // 初始化待排列数组元素为1、2、3...n for (i = 0; i < size; i++) { source[i] = i + 1; } while (true) { for (i = 0; i < size; i++) { cout << source[i]; } cout << endl; // 调用next_permutation查找下一个排列 if (!next_permutation(source, source + size)) { break; } } }