피너클의 it공부방
백준 1251 단어 나누기 (c++) : 피너클 본문
728x90
반응형
https://www.acmicpc.net/problem/1251
1251번: 단어 나누기
알파벳 소문자로 이루어진 단어를 가지고 아래와 같은 과정을 해 보려고 한다. 먼저 단어에서 임의의 두 부분을 골라서 단어를 쪼갠다. 즉, 주어진 단어를 세 개의 더 작은 단어로 나누는 것이다
www.acmicpc.net
그냥 전부다 한번씩 확인해보면 된다.
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
string str;
int main()
{
cin.tie(0);
cout.tie(0);
ios::sync_with_stdio(0);
cin >> str;
string ans = "zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz";
for (int i = 0; i < str.length() - 2; i++) {
for (int j = i + 1; j < str.length() - 1; j++) {
int a = i;
int b = j;
string s = "";
for (int k = a; k >= 0; k--) s += str[k];
for (int k = b; k > a; k--) s += str[k];
for (int k = str.length() - 1; k > b; k--) s += str[k];
if (ans > s) ans = s;
}
}
cout << ans << endl;
}
ans는 우선순위가 가장 뒤인 문자열이다.
728x90
반응형
'백준' 카테고리의 다른 글
백준 1039 교환 (c++) : 피너클 (0) | 2022.04.29 |
---|---|
백준 1331 나이트 투어 (c++) : 피너클 (0) | 2022.04.28 |
백준 9214 첫번째 항 (c++) : 피너클 (0) | 2022.04.27 |
백준 24508 나도리팡 (c++) : 피너클 (0) | 2022.04.24 |
백준 6588 골드바흐의 추축 (c++) : 피너클 (0) | 2022.04.21 |
Comments