Answers for "permutation with spaces"

C++
0

permutation with spaces

#include <bits/stdc++.h>

using namespace std;
void solve(string s,string op)
{
    if(s.size()==0)
    {
        cout<<op<<endl;
        return;
    }
    string op1=op;
    string op2=op;
    op2+=" ";
    op1+=s[0];
    op2+=s[0];
    s.erase(s.begin()+0);
    solve(s,op1);
    solve(s,op2);
}
int main()
{
    string s;
    cout<<"Enter the  string: ";
    cin>>s;
    string op="";
    op+=s[0];
    s.erase(s.begin()+0);
    solve(s,op);
    return 0;
}
Posted by: Guest on September-24-2021

Browse Popular Code Answers by Language