CodeFoeces-567B

题目

原题链接:B. Berland National Library

题意

给出n条图书馆的进出日志。问图书馆最小的大小。
用set进行模拟,若遇到不存在的与先前的退出,则计数器加1。每次操作后更新最大值。

代码

#include
using namespace std;
int main() {
    int n,no,ans=0;
    char comm;
    set room;
    cin>>n;
    for(int i=0; i>comm>>no;
        if(comm=='+') {
            room.insert(no);
        } else {
            if(room.find(no)!=room.end()) room.erase(no);
             else ans++;
        }
        int size=room.size();
        ans=max(ans,size);
    }
    cout<

你可能感兴趣的:(CodeFoeces-567B)