6687.Creating Strings

Time Limit: 1s Memory Limit: 512MB

Given a string, your task is to generate all different strings that can be created using its characters.

Input Format(From the terminal/stdin)

The only input line has a string of length $n$ . Each character is between az.

  • $1 \le n \le 8$

Output Format(To the terminal/stdout)

First print an integer $k$ : the number of strings. Then print $k$ lines: the strings in alphabetical order.

Sample Input

Copy
aabac
     \n

Sample Output

Copy
20
aaabc
aaacb
aabac
aabca
aacab
aacba
abaac
abaca
abcaa
acaab
acaba
acbaa
baaac
baaca
bacaa
bcaaa
caaab
caaba
cabaa
cbaaa
  \n
     \n
     \n
     \n
     \n
     \n
     \n
     \n
     \n
     \n
     \n
     \n
     \n
     \n
     \n
     \n
     \n
     \n
     \n
     \n
     \n
Source: CSES, Introductory Problems, 1622

Submit

请先 登录

© 2025 FAQs