http://codeforces.com/problemset/problem/245/E
画个函数图像你就知道代码怎么写了。
/*30ms,0KB*/
#include<bits/stdc++.h>
using namespace std;
const int mx = 305;
char s[mx];
int main()
{
gets(s);
int cnt = 0, ans = 0;
for (int i = 0; s[i]; ++i)
{
if (s[i] == '+')
{
++cnt;
ans = max(ans, cnt);
}
else
{
--cnt;
if (cnt < 0)
{
cnt = 0;
++ans;
}
}
}
printf("%d\n", ans);
return 0;
}