Notice
Recent Posts
Recent Comments
Link
250x250
«   2025/08   »
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
Archives
Today
Total
관리 메뉴

피너클의 it공부방

백준 1251 단어 나누기 (c++) : 피너클 본문

백준

백준 1251 단어 나누기 (c++) : 피너클

피너클 2022. 4. 27. 23:27
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
반응형
Comments