1159A A pile of stones

 

A. A pile of stones

time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

Vasya has a pile, that consists of some number of stones. nn times he either took one stone from the pile or added one stone to the pile. The pile was non-empty before each operation of taking one stone from the pile.

You are given nn operations which Vasya has made. Find the minimal possible number of stones that can be in the pile after making these operations.

Input

The first line contains one positive integer nn — the number of operations, that have been made by Vasya (1≤n≤1001≤n≤100).

The next line contains the string ss, consisting of nn symbols, equal to "-" (without quotes) or "+" (without quotes). If Vasya took the stone on ii-th operation, sisi is equal to "-" (without quotes), if added, sisi is equal to "+" (without quotes).

Output

Print one integer — the minimal possible number of stones that can be in the pile after these nn operations.

Examples

input

Copy

3
---

output

Copy

0

input

Copy

4
++++

output

Copy

4

input

Copy

2
-+

output

Copy

1

input

Copy

5
++-++

output

Copy

3

Note

In the first test, if Vasya had 33 stones in the pile at the beginning, after making operations the number of stones will be equal to 00. It is impossible to have less number of piles, so the answer is 00. Please notice, that the number of stones at the beginning can't be less, than 33, because in this case, Vasya won't be able to take a stone on some operation (the pile will be empty).

In the second test, if Vasya had 00 stones in the pile at the beginning, after making operations the number of stones will be equal to 44. It is impossible to have less number of piles because after making 44 operations the number of stones in the pile increases on 44 stones. So, the answer is 44.

In the third test, if Vasya had 11 stone in the pile at the beginning, after making operations the number of stones will be equal to 11. It can be proved, that it is impossible to have less number of stones after making the operations.

In the fourth test, if Vasya had 00 stones in the pile at the beginning, after making operations the number of stones will be equal to 33.

 

题意:有一堆石头,你可以加一块或者拿走一块石头,如果是拿走一块石头,保证这堆石头有足够的石头,添加的话就可以是没有石头。现在给了n次操作,然后一个n长度的字符串,+就是添加,-就是减少,经过n次操作后,输出当前这堆石头有多少个石头。

题解:模拟

python:

n=int(input())
s=input()
ans=0
for i in s:
          if i=='+':ans+=1
          else:ans=max(ans-1,0)
print(ans)

c++: 

#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,ans=0;
    string s;
    cin>>n;
    cin>>s;
    for(int i=0; i<n; i++)
        if(s[i]=='+') ans++;
        else ans=ans>0?--ans:0;
    cout<<ans<<endl;
    return 0;
}

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

落凡尘.

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值