CROC-MBTU 2012, Elimination Round / 245E Mishap in Club (想法题)

来源:互联网 发布:windows 平板电脑应用 编辑:程序博客网 时间:2024/05/22 12:08

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;}

0 0
原创粉丝点击