Friday, February 14, 2020

string

#include<iostream>
using namespace std;
void swap(char*a,char*b){
  char c;
  c=*a;
  *a=*b;
  *b=c;
}
void permute(string s,int i,int n)
{
  if(i==n)
    cout<<s<<"\n";
  else{
    for(int j=i;j<s.length();j++){
      swap(s[i],s[j]);
      permute(s,i+1,n);
      swap(s[i],s[j]);
    }
  }
}
int main(){
  string s;
  cin>>s;
  permute(s,0,s.length());
  return 0;}

No comments:

Post a Comment