permutation with spaces

Solutions on MaxInterview for permutation with spaces by the best coders in the world

showing results for - "permutation with spaces"
Luis
02 Jan 2017
1#include <bits/stdc++.h>
2
3using namespace std;
4void solve(string s,string op)
5{
6    if(s.size()==0)
7    {
8        cout<<op<<endl;
9        return;
10    }
11    string op1=op;
12    string op2=op;
13    op2+=" ";
14    op1+=s[0];
15    op2+=s[0];
16    s.erase(s.begin()+0);
17    solve(s,op1);
18    solve(s,op2);
19}
20int main()
21{
22    string s;
23    cout<<"Enter the  string: ";
24    cin>>s;
25    string op="";
26    op+=s[0];
27    s.erase(s.begin()+0);
28    solve(s,op);
29    return 0;
30}
31
32