#include <iostream> #include<stack> using namespace std; int main() { stack<long long> stack1; int Number = 0; while (scanf("%d", &Number) != EOF) { //此处必须写上“!=EOF”,否则会超时! for (int i = 0; i < Number; i++) { long long number; scanf("%lld", &number); stack1.push(number); } for (int i = 0; i < Number; i++) { printf("%lld ", stack1.top()); //先读顶部元素 stack1.pop();//再出栈 } printf("\n"); } }