https://www.acmicpc.net/problem/9081
9081번: 단어 맞추기
입력의 첫 줄에는 테스트 케이스의 개수 T (1 ≤ T ≤ 10)가 주어진다. 각 테스트 케이스는 하나의 단어가 한 줄로 주어진다. 단어는 알파벳 A~Z 대문자로만 이루어지며 항상 공백이 없는 연속된 알
www.acmicpc.net
[난이도] Gold4
[유형] 구현
[풀이]
next_permutation을 이용해서 두번째로 나오는 숫자를 구하면 된다.
#include <string>
#include <iostream>
#include <algorithm>
using namespace std;
int tc;
int main(){
cin >> tc;
while(tc--){
string s,ans;
cin >> s;
int cnt=0;
do{
ans = s;
if(++cnt==2) break;
}while(next_permutation(s.begin(),s.end()));
cout << ans << '\n';
}
}
https://github.com/has2/Problem-Solving/blob/master/boj-solved.ac/Gold4/9081.cpp
'Problem-Solving > BOJ' 카테고리의 다른 글
[BOJ/백준][Gold3] 2216 : 문자열과 점수 (C++) (0) | 2021.03.01 |
---|---|
[BOJ/백준][Gold4] 5913 : 준규와 사과 (C++) (0) | 2021.03.01 |
[BOJ/백준][Gold4] 13422 : 도둑 (C++) (0) | 2021.02.14 |
[BOJ/백준][Gold4] 20058 : 마법사 상어와 파이어스톰 (C++) (0) | 2021.02.14 |
[BOJ/백준][Gold4] 12970 : AB (C++) (0) | 2021.02.14 |