文章
17
粉丝
166
获赞
6
访问
143.7k
#include <bits/stdc++.h>
using namespace std;
string a;
int main()
{
cin >> a;
sort(a.begin(), a.end());
do
{
cout << a;
cout << endl;
}while(next_permutation(a.begin(), a.end()));
return 0;
}
djs解法:
#include <bits/stdc++.h>
using namespace std;
string s;
bool st[10];
vector<char> vec;
void dfs(int u)
{
if(u == s.size())
{
for(auto c: vec) cout << c;
cout << endl;
return;
}
for(int i = 0; i < s.size(); i++)
{
if(!st[i])
{
st[i] = true;
vec.push_back(s[i]);
dfs(u + 1);
st[i] = false;
vec.pop_back();
}
}
}
int main()
{
cin >> s;
sort(s.begin(), s.end());
dfs(0);
return 0;
}
登录后发布评论
暂无评论,来抢沙发