반응형
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <stack>
#include <vector>
#include <math.h>
using namespace std;
int main() {
//freopen("input.txt.txt","rt",stdin);
int n,i,arr[31],order=1,pos=1,cnt=0;
scanf("%d", &n);
for(i=1;i<=n;i++){
scanf("%d", &arr[i]);
}
stack<int> s;
string ans = "";
for(i=1;i<=n;i++){
s.push(arr[i]);
ans+='P';
while(!s.empty()&&s.top()==order){
ans+='O';
order++;
s.pop();
}
}
if(s.empty()) printf("%s\n",ans.c_str());
else printf("impossible\n");
return 0;
}
기차 교차로 문제
반응형
'Algorithm > etc' 카테고리의 다른 글
이진트리 깊이우선탐색(DFS) (0) | 2022.01.14 |
---|---|
재귀함수로 2진수 만들기 (0) | 2022.01.14 |
N진수 출력 C++ (0) | 2022.01.12 |
투포인터 활용, ugly numbers (0) | 2022.01.12 |
배열, 벡터에서 0 이상 찾기 (0) | 2022.01.10 |