Little Jay

[C++] 백준 6443번 - 애너그램 본문

알고리즘/BOJ

[C++] 백준 6443번 - 애너그램

Jay, Lee 2021. 8. 25. 21:38

몰랐는데 C++에 prev_permutation이라는 강력한 기능이 있었다!

#include <iostream>
#include <vector>
#include <algorithm>
#include <limits>
using namespace std;

vector<string> v;

void permutation(string& s) {
	sort(s.begin(), s.end(), greater<>());
	do {
		//cout << s << endl;
		v.push_back(s);
	} while (prev_permutation(s.begin(), s.end()));
}

int main() {

	int n;
	cin >> n;
	for (int i = 0; i < n; i++) {
		string s;
		cin >> s;
		permutation(s);

		for (int j = v.size() - 1; j >= 0; j--) {
			cout << v[j] << "\n";
		}
		v.clear();

	}

	return 0;
}

'알고리즘 > BOJ' 카테고리의 다른 글

[C++] 백준 5622번 - 다이얼  (0) 2021.09.02
[C++] 백준 1149번 - RGB거리  (0) 2021.08.30
[C++] 백준 1747번 - 소수&팰린드롬  (0) 2021.08.23
[C++] 백준 5430번 - AC  (0) 2021.08.23
[C++] 백준 13241번 - 최소공배수  (0) 2021.08.21
Comments