※ 글쓴이는 취미로 코딩을 익혀보는 사람이라 정확하지 않은 내용을 담고 있을 수 있다 ※

 

이번에 볼 문제는 백준 5360번 문제인 Next Permutation이다.
문제는 아래 링크를 확인하자.

https://www.acmicpc.net/problem/5360 

 

5360번: Next Permutation

Given an integer A, only other integers that are permutations of A are useful. All other numbers are useless. Find the next largest integer B, where the digits in B is a permutation of the digits of A. For example, suppose A=2413, then the next largest per

www.acmicpc.net

숫자로 이루어진 문자열의 다음 순열을 구하는 문제이다.

 

algorithm헤더의 next_permutation 함수를 이용해 간단히 구현하는 것으로 문제를 해결하자.

 

아래는 제출한 소스코드이다.

#include <iostream>
#include <string>
#include <algorithm>
using namespace std;

int T;

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);

	cin >> T;
	while (T--) {
		string s; cin >> s;
		if (next_permutation(s.begin(), s.end())) cout << s << '\n';
		else cout << "USELESS\n";
	}
}
728x90

'BOJ' 카테고리의 다른 글

[BOJ 5340 // C++] Secret Location  (0) 2022.12.22
[BOJ 5342 // C++] Billing  (0) 2022.12.22
[BOJ 5292 // C++] Counting Swann's Coins  (0) 2022.12.22
[BOJ 15179 // C++] Golf Croquet  (0) 2022.12.22
[BOJ 10190 // C++] Acronyms  (0) 2022.12.22

+ Recent posts