cf 245 E. Mishap in Club

E. Mishap in Club
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Polycarpus just has been out of luck lately! As soon as he found a job in the "Binary Cat" cafe, the club got burgled. All ice-cream was stolen.

On the burglary night Polycarpus kept a careful record of all club visitors. Each time a visitor entered the club, Polycarpus put down character "+" in his notes. Similarly, each time a visitor left the club, Polycarpus put character "-" in his notes. We know that all cases of going in and out happened consecutively, that is, no two events happened at the same time. Polycarpus doesn't remember whether there was somebody in the club at the moment when his shift begun and at the moment when it ended.

Right now the police wonders what minimum number of distinct people Polycarpus could have seen. Assume that he sees anybody coming in or out of the club. Each person could have come in or out an arbitrary number of times.

Input

The only line of the input contains a sequence of characters "+" and "-", the characters are written one after another without any separators. The characters are written in the order, in which the corresponding events occurred. The given sequence has length from 1 to 300 characters, inclusive.

Output

Print the sought minimum number of people

Sample test(s)
Input
+-+-+
Output
1
Input
---
Output
3

其实求++和--的最大差值了。囧。。。
View Code
 1 #include<stdio.h>
 2 #include<string.h>
 3 int main()
 4 {
 5     int max,len;
 6     int sum1,sum2;
 7     char str[310];
 8     while(~scanf("%s",str))
 9     {
10         max=0;
11         len=strlen(str);
12         for(int i=0;i<len;i++)
13         {
14             sum1=0;sum2=0;
15             for(int j=i;j<len;j++)
16             {
17                 if(str[j]=='+')
18             {
19                 sum1++;
20             }
21             else 
22             {
23                 sum2++;
24             }
25             if(sum1>sum2&&max<sum1-sum2)
26             max=sum1-sum2;
27             else if(sum2>sum1&&max<sum2-sum1)
28             max=sum2-sum1;
29             }
30              
31         }
32         printf("%d\n",max);
33     }
34 }

 

posted on 2012-11-20 23:44  仁者无敌8勇者无惧  阅读(319)  评论(0编辑  收藏  举报

导航