알고리즘 문제/BOJ
16719번 ZOAC
parkit
2019. 1. 2. 22:15
728x90
반응형
https://www.acmicpc.net/problem/16719
나한테는 되게 어려웠다.
정답 코드처럼 생각은 했었는데, 왜 구현이 어려웠을까..
참고로, min_element()는 나도 처음 써보는 STL이다.
http://blog.naver.com/kks227/220246803499
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 | #include <iostream> #include <queue> #include <stack> #include <cstdio> #include <vector> #include <cstring> #include <string> #include <math.h> #include <algorithm> #include <map> using namespace std; string s; bool used[101] = { false, }; void zoac(int Start, int End) { if (Start > End) return; char c = *min_element(s.begin() + Start, s.begin() + End + 1); int p = 0; for (p = Start; p <= End; p++) { if (s.at(p) == c) { used[p] = true; break; } } for (int i = 0; i < s.length(); i++) if (used[i]) printf("%c", s.at(i)); printf("\n"); zoac(p + 1, End); zoac(Start, p - 1); } int main(void) { int MIN = 987654321, idx = 0; cin >> s; zoac(0, s.length() - 1); return 0; } | cs |
728x90
반응형