您的位置:首页 > 编程语言 > C语言/C++

CodeForces 567B-Berland National Library

2016-07-18 14:44 295 查看

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;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  c语言