TopCoder

User's AC Ratio

NaN% (0/0)

Submission's AC Ratio

NaN% (0/0)

Tags

Description

stack 定義如下:

template<typename T>
struct Stack {  
    T arr[1024];
    int top = 0;
};

請分別撰寫push、pop和isEmpty函式,說明如下:
push:將新資料放入Stack,並回傳修改後的Stack,保證輸入不會超過1024

pop:移除Stack最上面的資料,並回傳修改後的Stack

isEmpty:回傳true(1)或false(0)

範例程式:

#include <iostream>

template <typename T>
struct Stack {
    T arr[1024];
    int top = 0;
};

// 你的程式會放在這裡

int main() {
    int event;
    std::cin >> event;
    Stack<int> s; // 這裡T指的是int
    for (int i = 0; i < event; i++) {
        std::string command;
        std::cin >> command;
        if (command == "push") {
            int data; // 這裡T指的是int
            std::cin >> data;
            s = push(s, data);
        } else {
            if (isEmpty(s) != true) {
                std::cout << s.arr[s.top - 1] << "\n";
                s = pop(s);
            }
        }
    }
    std::cout << "\n";
}

Input Format

Output Format

Hints

Problem Source

NEOJ Problem 446

Subtasks

No. Testdata Range Constraints Score
1 0 25
2 1 25
3 2 25
4 3 25

Testdata and Limits

No. Time Limit (ms) Memory Limit (VSS, KiB) Output Limit (KiB) Subtasks
0 1000 65536 65536 1
1 1000 65536 65536 2
2 1000 65536 65536 3
3 1000 65536 65536 4