-
카테고리
-
세부 분야
알고리즘 · 자료구조
-
해결 여부
미해결
질문있습니다
21.07.05 11:29 작성 조회수 40
0
삭제된 글입니다
답변을 작성해보세요.
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
답변 2