0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

競プロ日記#25/04/11

Last updated at Posted at 2025-04-11

アルゴ式-積ん読

  • 今回の問題は残っている本を答えるのではなくて読んだ本(消化した本)を答えるのでstackを使って追加時はpush、読み終え時はtopでアクセス→popで削除で良い
  • がしかし結局vectorで上手くやる方が柔軟性があって良い
#include <bits/stdc++.h>
#include <algorithm>
#include <stack>
using namespace std;

using Graph = vector<vector<int>>;

int main() {
    int Q;
    cin >> Q;
    vector<string> S;

    for (int i = 0;i < Q;i++){
        int n;
        cin >> n;
        if(n == 1){
            string s;
            cin >> s;
            S.push_back(s);
        }else{
            cout << S.back() << endl;
            S.pop_back();
        }
    }
    
    
}
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?