No Rules Rules

세 부분 (feat. 백준, 2993번) 본문

생활/코테

세 부분 (feat. 백준, 2993번)

개발하는 완두콩 2022. 9. 6. 16:01
728x90
반응형

세 부분
https://www.acmicpc.net/problem/2993

 

2993번: 세 부분

첫째 줄에 원섭이가 고른 단어가 주어진다. 고른 단어는 알파벳 소문자로 이루어져 있고, 길이는 3보다 크거나 같고, 50보다 작거나 같다.

www.acmicpc.net

 

반응형

 

// woohyeon.kim
// kim519620.tistory.com
#include <iostream>
#include <string>
#include <set>
#include <algorithm>
using namespace std;
int main() {
	ios::sync_with_stdio(false), cin.tie(NULL);
	string str, t1, t2, t3;
	cin >> str;
	register int size = str.size();
	set<string> ans;
	for (register int i = 1, j, k; i < size; ++i)
		for (j = 1; j < size - i; ++j) {
			k = size - (i + j);
			t1 = str.substr(0, i);
			t2 = str.substr(i, j);
			t3 = str.substr(i + j, k);
			reverse(t1.begin(), t1.end());
			reverse(t2.begin(), t2.end());
			reverse(t3.begin(), t3.end());
			ans.insert(t1 + t2 + t3);
		}
	cout << *ans.begin();
	return 0;
}
// *&)*@*

 

 

아래 "단어 나누기" 와 동일한 문제입니다.

 

단어 나누기 (feat. 백준, 1251번)

단어 나누기 https://www.acmicpc.net/problem/1251 1251번: 단어 나누기 알파벳 소문자로 이루어진 단어를 가지고 아래와 같은 과정을 해 보려고 한다. 먼저 단어에서 임의의 두 부분을 골라서 단어를 쪼갠

kim519620.tistory.com

 

 

728x90
반응형
Comments