You are not logged in. Please login at www.codechef.com to post your questions!

×

How to print permutations of string in lexicographical order?

Approach to solve this question.

asked 24 Aug '16, 16:37

saksham458's gravatar image

0★saksham458
4649
accept rate: 50%


Sort the string in increasing order ... and then prints it permutations till all the characters are not in descending order

link

answered 24 Aug '16, 21:42

devil_1909's gravatar image

4★devil_1909
11
accept rate: 0%

Just use the inbuilt functions:
https://ideone.com/VrUi4X

#include <bits/stdc++.h> 
using namespace std;

int main(){
string s;
cin >> s;

sort(s.begin(), s.end());

while(next_permutation(s.begin(), s.end()))
      cout << s << endl;

return 0;
}
link

answered 24 Aug '16, 23:57

coderaashir's gravatar image

4★coderaashir
1082
accept rate: 28%

toggle preview
Preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported
  • mathemetical formulas in Latex between $ symbol

Question tags:

×1,407
×644
×181
×8

question asked: 24 Aug '16, 16:37

question was seen: 761 times

last updated: 24 Aug '16, 23:57