Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <cstdio>
- #include <iostream>
- #include <string>
- using namespace std;
- int arr[10001];
- int idx = 0;
- void push(int num) {
- arr[idx++] = num;
- }
- void top() {
- if(idx == 0) printf("-1\n");
- else printf("%d\n", arr[idx - 1]);
- }
- void size() {
- printf("%d\n", idx);
- }
- void empty() {
- if(idx == 0) printf("1\n");
- else printf("0\n");
- }
- void pop() {
- if(idx == 0) printf("-1\n");
- else {
- top();
- idx--;
- }
- }
- int main(void)
- {
- int n;
- scanf("%d", &n);
- while(n--) {
- string order;
- cin >> order;
- if(order == "push") {
- int num;
- scanf("%d", &num);
- push(num);
- }
- else if(order == "pop") pop();
- else if(order == "top") top();
- else if(order == "size") size();
- else if(order == "empty") empty();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement