• 카테고리

    질문 & 답변
  • 세부 분야

    알고리즘 · 자료구조

  • 해결 여부

    미해결

질문있습니다

21.07.05 11:29 작성 조회수 40

0

삭제된 글입니다

답변 2

·

답변을 작성해보세요.

0

김혁수님의 프로필

김혁수

질문자

2021.07.06

#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <stack>

using namespace std;

int main() {
int n;
scanf("%d",&n);
vector<int> a(n+2);
for (int i = 1; i <= n; i++){
	scanf("%d",&a[i]);
}

stack<int> s;
vector<char> c;

s.push(a[1]);
c.push_back('P');
int i = 2;
int j = 1;

while(i<=n || j <= n ){

	if(s.top() == j){
		s.pop();
		c.push_back('O');
		j++;
	}
	else {
		s.push(a[i]);
		c.push_back('P');
		i++;
	}
}

if(!s.empty()) printf("impossible");
else {
	for (int k = 0; k<c.size();k++) printf("%c",c[k]); 
}

return 0;
}

0

안녕하세요^^

위에 질문자님 처럼

{;} 버튼으로 코드를 올려주세요. 들여쓰기가 안된 것은 분석하기 힘듭니다.