반응형

문제 출처 :


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



알고리즘 분석 :


문제 해결에 필요한 사항

1. 순열


결국 이 문제가 요구하는 것은 '다음 순열이 존재하는가?'이다.


다음 순열이 존재하면 그 순열을 출력하고, 


다음 순열이 존재하지 않으면(현재 입력된 수가 4321처럼 마지막 순열이면) 0을 출력하라는 의미이다.













소스 코드 : 


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
using namespace std;
 
int main()
{
    string str;
    cin >> str;
 
    bool chk = next_permutation(str.begin(), str.end());
 
    if (chk)
        cout << str;
    else
        cout << '0';
    return 0;
}
 
//                                                       This source code Copyright belongs to Crocus
//                                                        If you want to see more? click here >>
Crocus


반응형

'Applied > 알고리즘 문제풀이' 카테고리의 다른 글

[14653번] 너의이름은  (0) 2017.08.07
[2108번] 통계학  (0) 2017.08.06
[14659번] 한조서열정리하고옴ㅋㅋ  (0) 2017.08.04
[2306번] 유전자  (0) 2017.08.03
[2551번] 두 대표 자연수  (0) 2017.08.03