백준 16719번 ZOAC
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 | #include <iostream> #include <string> #include <vector> #include <algorithm> using namespace std; int visited[101]; int main(void){ ios_base::sync_with_stdio(0); cin.tie(0); string s; cin >> s; for (int i = 0; i < s.size(); i++) { vector<pair<string,int> > words; for (int j = 0; j < s.size(); j++) { if (!visited[j]) { string temp; for (int k = 0; k < s.size(); k++) { if (j == k || visited[k]) { temp += s[k]; } } words.push_back(make_pair(temp,j)); } } sort(words.begin(), words.end()); cout << words[0].first << endl; visited[words[0].second] = true; } return 0; } | cs |
출처:https://www.acmicpc.net/problem/16719
분류가 분할정복으로 되어있었던거 같은데 맞는지 모르겠네요.
글자를 한글자씩 추가해주는데 이미 추가했던 문자는 visited에 저장해놓고
temp에 단어를 만들때마다 words에 추가시킨뒤 정렬시키면 사전순으로 배열이됩니다.
'알고리즘 > BAEKJOON' 카테고리의 다른 글
| 백준 11404번 플로이드 (0) | 2019.03.26 |
|---|---|
| 백준 15325번 Doktor (0) | 2019.03.25 |
| 백준 1158번 조세퍼스 문제 (0) | 2019.03.24 |
| 백준 1149번 RGB거리 (0) | 2019.03.23 |
| 백준 16463번 13일의 금요일 (0) | 2019.03.22 |