说实话 题目的意思我根本就不不懂。。。。 看到给出的样例就知道是给出字符串的全排列同样的 利用next_permutation()函数 (这个函数的作用就是给出你的数组的下一个全排列,对应的还有prev_permutation())函数
记得在得到数据后先进行一次sort
#include<stdio.h> #include<iostream> #include<algorithm> #include<string> using namespace std; bool cmp(char a, char b){ return a < b; } int main(){ int n; scanf_s("%d", &n); while (n--){ string s; cin >> s; sort(s.begin(),s.end(),cmp); do{ cout << s << endl; } while (next_permutation(s.begin(), s.end())); cout << endl; } return 0; }
uva10098 Generating Fast
最新推荐文章于 2018-11-29 23:07:55 发布