• Home
  • About
    • changsoooooo's Blog photo

      changsoooooo's Blog

      changsoooooo's Blog.

    • Learn More
    • Twitter
    • Facebook
    • Instagram
    • Github
    • Steam
  • 일상
  • 교육
    • 교육학
    • 정보 컴퓨터 교육
    • 임용
  • 개발
  • 잡지식
  • 한국사
  • Projects

1874(스택수열)

08 Nov 2020

Reading time ~1 minute

#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <math.h>
#include <list>

using namespace std;
int main(){
	ios::sync_with_stdio(false);
	cin.tie(NULL);

	vector<int> ve;
	vector<char> v2;
	int n;
	cin >> n;

	int t = 1;
	int top=0;
	int err = 1;

	for (int i = 1; i <= n; i++)
	{
		
		int a;
		cin >> a;
		for (;t<=a;)
		{
			ve.push_back(t);
			top = t;
			v2.push_back('+');
			t++;
		}
		if (a==top)
		{
			v2.push_back('-');
			ve.pop_back();
			if (ve.size()>0)
			{
				top = ve.back();
			}
			else
			{
				top = -1;
			}
			
			
		}
		else {

			err=-1;
		}
	}
	if (err==-1)
	{
		cout << "NO\n";
	}
	else
	{
		for (size_t i = 0; i < v2.size(); i++)
		{
			cout << v2[i] << "\n";
		}
	}

}


Share Tweet +1