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

+ Recent posts