B.cpp 507 B

1234567891011121314151617181920212223242526
  1. //
  2. // Created by liuhuan on 18-10-29.
  3. //
  4. #include <bits/stdc++.h>
  5. using namespace std;
  6. int main() {
  7. int n, q;
  8. cin >> n >> q;
  9. vector<stack<int>> S(n);
  10. while (q--) {
  11. int op, t;
  12. cin >> op >> t;
  13. if (op == 0) {
  14. int x;
  15. cin >> x;
  16. S[t].push(x);
  17. } else if (op == 1) {
  18. if (S[t].size()) cout << S[t].top() << endl;
  19. } else if (op == 2) {
  20. if (S[t].size()!=0) S[t].pop();
  21. }
  22. }
  23. return 0;
  24. }