C++/백준 C++

C++ 1874 스택 수열 [스택]

CE : 하랑 2024. 10. 21. 17:52

 

 

 

코드

#include <iostream>
#include <vector>
#include <stack>

int main()
{
	std::stack<int> ST;
	std::vector<char> Result;
	int Ncount = 1;

	int n;
	std::cin >> n;

	for (int i = 0; i < n; i++)
	{
		int num;

		std::cin >> num;

		while (true)
		{
			if (Ncount > num)
			{
				break;
			}

			ST.push(Ncount);
			Result.push_back('+');
			++Ncount;
		}
		

		if (ST.top() == num)
		{
			ST.pop();
			Result.push_back('-');
		}
		else
		{
			std::cout << "NO\n";
			return 0;
		}
	}

	for (int i = 0; i < Result.size(); i++)
	{
		std::cout << Result[i] << "\n";
	}
	return 0;
}