https://www.acmicpc.net/problem/2493
2493번: 탑
첫째 줄에 탑의 수를 나타내는 정수 N이 주어진다. N은 1 이상 500,000 이하이다. 둘째 줄에는 N개의 탑들의 높이가 직선상에 놓인 순서대로 하나의 빈칸을 사이에 두고 주어진다. 탑들의 높이는 1
www.acmicpc.net
구글 참조 해서 풀었다 - stack은 너무 어렵다
#include <iostream>
#include <stack>
#include <utility>
using namespace std;
int main() {
int num;
scanf("%d", &num);
int count = 0;
stack<pair<int, int>> s;
pair<int, int> p;
int input;
while (count < num)
{
scanf("%d", &input);
p = make_pair(count + 1, input);
while (!s.empty()) {
if (s.top().second > input) {
printf("%d ", s.top().first);
break;
}
s.pop();
}
if (s.empty())
printf("0 ");
s.push(p);
count++;
}
return 0;
}
'c++ > 프로그래머스' 카테고리의 다른 글
프로그래머스 : [1차] 뉴스 클러스터링 c++ (0) | 2021.09.25 |
---|---|
프로그래머스 : 등굣길 c++ (DP 연습) (0) | 2021.06.23 |
프로그래머스 : N으로 표현 c++ (0) | 2021.06.21 |
프로그래머스 : 큰 수 만들기 c++ (0) | 2021.06.20 |
프로그래머스 : 조이스틱 c++ (1) | 2021.06.20 |