[백준/BOJ] 1464. 뒤집기 3 [Gold 5]

jychan99·2022년 1월 15일
0
post-thumbnail
  1. 뒤집기 3

문제출처 : https://www.acmicpc.net/problem/1464

code

#include <iostream>
#include <string>
#include <algorithm>
using namespace std;

int main()
{
	string S, temp;
	int len, i;

	cin >> S;
	len = S.length();

	temp.push_back(S[0]);
	for (i = 1; i < len; i++)
	{
		if (temp[0] >= S[i])
		{
			reverse(temp.begin(), temp.end());
			temp.push_back(S[i]);
			reverse(temp.begin(), temp.end());
		}
		else
		{
			temp.push_back(S[i]);
		}
	}

	cout << temp;

	return 0;
}

reverse함수와 문자열헤더함수를 적절히 이용하면 어렵지 않다.

profile
내가 지금 두려워 하고 있는 일이 바로 내가 지금 해야 할 일이다. 🐥

0개의 댓글