使用STL自带的 栈 即可
AC code:
#include <bits/stdc++.h> using namespace std; stack <int>st; int main() { int n; cin>>n; while(n--){ int x; cin>>x; st.push(x); } while(!st.empty()){ cout<<st.top()<<' '; st.pop(); } return 0; }
#include <bits/stdc++.h> using namespace std;
int main() { int a[100], n; cin >> n; for (int i = 1; i <= n; i++) { cin >> a[i]; } for (int j = n; j > 0; j--) { cout << a[j] << " "; } return 0; }
使用您的 蒙青创OJ 通用账户