-
Maximum Element해커랭크(HackerRank) 2018. 8. 19. 17:21반응형
1. 문제
2. 알고리즘
키워드 - 구현, 스택
3. 코드
12345678910111213141516171819202122232425262728293031323334353637383940#include <cmath>#include <cstdio>#include <vector>#include <iostream>#include <algorithm>#include <stack>using namespace std;int main() {/* Enter your code here. Read input from STDIN. Print output to STDOUT */stack<long int> s, m;m.push(-1);int n; cin>>n;int i = 0;while(i<n){int x;cin>>x;if(x==1) {int z ;cin>>z;s.push(z);if(z >= m.top())m.push(z);}else if(x==2){int q = s.top();if(q == m.top())m.pop();s.pop();}else if(x==3){cout << m.top() << endl;//m.pop();}i++;}return 0;}cs 반응형'해커랭크(HackerRank)' 카테고리의 다른 글
Print the Elements of a Linked List (0) 2018.08.19 Insert a Node at the Tail of a Linked List (0) 2018.08.19 Print in Reverse (0) 2018.08.19 Reverse a linked list (0) 2018.08.19 Compare two linked lists (0) 2018.08.19