CodeForces 567B-Berland National Library

来源:互联网 发布:关于windows格式化磁盘 编辑:程序博客网 时间:2024/05/21 07:33

CodeForces 567B-Berland National Library

题目大意:+代表有人进入,-代表有人出来,后面数字为编号,有的人可能一开始就在屋子里,写出在屋子里的最大容量至少为多少

解题思路:模拟,用o算现有人数,用max记录最大人数,加入出现未出现的编号出来就让max+1。

#include <stdio.h>#include <string.h>#include <math.h>#include <iostream>using namespace std;int main() {    int n;    char b;    long long int s;    long long int a[1000];    int x = 0;    int max = 0;    int o = 0;    cin >> n;    getchar();    while(n--) {        b = getchar();        scanf("%lld", &s);        getchar();        if(b == '-') {            for(int i = 0; i <= x; i++) {                if(i == x) {                    max++;                    break;                }                if(a[i] == s) {                    a[i] = -1;                    o--;                    break;                }            }        }        else if(b == '+') {            o++;            a[x] = s;            x++;        }        if(o > max)            max = o;    }    printf("%d\n", max);    return 0;}
0 0