stackクラス
#include <bits/stdc++.h> #define REP(i,n) for(int i=0; i<(n); i++) #define REP2(i,x,n) for(int i=x; i<(n); i++) using namespace std; int main (){ cin.tie(0); ios::sync_with_stdio(false); int n; cin >> n; stack<int> st; int a; REP(i,n){ cin >> a; st.push(a);//push() -> 値を「追加」する } REP(i,n){ cout << st.top() << endl;//top() -> 末尾要素を「参照」する st.pop();//pop() 末尾要素を「削除」する } return 0; }
stackクラス....を学習しました。
pushした物をそのまま取り出すので、
入力が 1 2 3 4 5 6 7 8 9 10 だった場合、
出力は 10 9 8 7 6 5 4 3 2 1 となる。