출처: https://cses.fi/problemset/task/1622
문제 설명
Given a string, your task is to generate all different strings that can be created using its characters.
입력
The only input line has a string of length n. Each character is between a–z.
출력
First print an integer k: the number of strings. Then print k lines: the strings in alphabetical order.
입력 예
aabac
출력 예
20
aaabc
aaacb
aabac
aabca
aacab
aacba
abaac
abaca
abcaa
acaab
acaba
acbaa
baaac
baaca
bacaa
bcaaa
caaab
caaba
cabaa
cbaaa
제약조건
1 ≤ n ≤ 8
문제 풀이 내용
문자열을 읽어 들인다음, 정렬한다. next_permutation() 기능을 이용해서 새로운 문자열을 만들고 set<string>에 저장한다. set에 저장된 문자열 개수와 문자열들을 출력한다.
프로그램 내용
int main()
{
cin >> in_str;
set <string> out_str;
sort(in_str.begin(), in_str.end());
do {
out_str.insert(in_str);
} while (next_permutation(in_str.begin(), in_str.end()));
cout << out_str.size() << endl;
for (auto it : out_str)
cout << it << endl;
Introductory problems ( link )
'CSES' 카테고리의 다른 글
CSES 1. Chessboard and Queens (1624) (0) | 2019.09.23 |
---|---|
CSES 1. Apple Division (1623) (0) | 2019.09.23 |
CSES 1. Palindrome Reorder (1755) (0) | 2019.09.23 |
CSES 1. Coin Piles (1754) (0) | 2019.09.23 |
CSES 1. Trailing Zeros (1618) (0) | 2019.09.23 |