题目链接
Vasya has a pile, that consists of some number of stones. n 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 n 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 n — the number of operations, that have been made by Vasya (1≤n≤100).

The next line contains the string s, consisting of n symbols, equal to “-” (without quotes) or “+” (without quotes). If Vasya took the stone on i-th operation, si is equal to “-” (without quotes), if added, si is equal to “+” (without quotes).

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

input

3
---

output

0

input

4
++++

output

4

input

2
-+

output

1

input

5
++-++

output

3

Note
In the first test, if Vasya had 3 stones in the pile at the beginning, after making operations the number of stones will be equal to 0. It is impossible to have less number of piles, so the answer is 0. Please notice, that the number of stones at the beginning can’t be less, than 3, 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 0 stones in the pile at the beginning, after making operations the number of stones will be equal to 4. It is impossible to have less number of piles because after making 4 operations the number of stones in the pile increases on 4 stones. So, the answer is 4.

In the third test, if Vasya had 1 stone in the pile at the beginning, after making operations the number of stones will be equal to 1. 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 0 stones in the pile at the beginning, after making operations the number of stones will be equal to 3.

题意:给你一串只有’+’,’-'组成的字符串,‘+’代表给石子堆加一,‘-’代表给石子堆减一,初始石子堆为0,在每一次操作之前,保证石子堆非空,问你将字符串中的命令执行完之后石子堆有多少个
题解:模拟,注意如果石子堆为0,那么将不会执行‘-’操作

#include<bits/stdc++.h>
using namespace std;
int main(){char c;int n,ans = 0;scanf("%d",&n);for(int i = 0;i < n;i++){scanf(" %c",&c);if(c == '-' && ans - 1 >= 0) ans--;else if(c == '+') ans++;}printf("%d\n",ans);return 0;
}

A. A pile of stones相关推荐

  1. Codeforces 1159A A pile of stones

    题目链接:http://codeforces.com/problemset/problem/1159/A 题意:初始石头堆石子数未知,求进行 n 次加减操作后,石头堆石子数最小的可能是多少. 思路:正 ...

  2. Moving stones(暴力+思维)

    链接:https://ac.nowcoder.com/acm/contest/5891/D 来源:牛客网 题目描述 One day, GK was getting very bored with pa ...

  3. 【LeetCode 1000】 Minimum Cost to Merge Stones

    题目描述 There are N piles of stones arranged in a row. The i-th pile has stones[i] stones. A move consi ...

  4. 19级爪哇程序设计新手赛(题解)

    19级爪哇程序设计新手赛(题解) A.1+1 HDU - 1228 kk的英语作业,有两个小于100的正整数A和B,计算A+B. A和B由对应的英文单词给出. Input 测试输入包含若干测试用例,每 ...

  5. E. Tree(The 2019 ACM-ICPC China Shannxi Provincial Programming Contest)(树链剖分+线段树)

    4000ms 262144K judge:计蒜客 Description Ming and Hong are playing a simple game called nim game. They h ...

  6. [ICPC 北京 2017 J题]HihoCoder 1636 Pangu and Stones

    #1636 : Pangu and Stones 时间限制:1000ms 单点时限:1000ms 内存限制:256MB 描述 In Chinese mythology, Pangu is the fi ...

  7. *【2019牛客暑期多校训练营(第三场)- G】Removing Stones(分治)

    题干: 链接:https://ac.nowcoder.com/acm/contest/883/G 来源:牛客网 Summer vacation is coming and Mark has retur ...

  8. 2017ICPC北京 J:Pangu and Stones(区间DP)

    #1636 : Pangu and Stones 时间限制:1000ms 单点时限:1000ms 内存限制:256MB 描述 In Chinese mythology, Pangu is the fi ...

  9. hihocoder1636-Pangu and Stones

    #1636 : Pangu and Stones 时间限制:1000ms 单点时限:1000ms 内存限制:256MB 描述 In Chinese mythology, Pangu is the fi ...

最新文章

  1. 脑电分析系列[MNE-Python-15]| Epochs数据可视化
  2. python3.6.4安装教程-Centos7 安装Python3.6.4
  3. (58)模拟线程切换——添加挂起、恢复线程功能
  4. mysql数据库没启动命令_mysql数据库服务启动和停止命令介绍(转载)
  5. 读书笔记---图解HTTP(一)
  6. ML.NET 推荐引擎中一类矩阵因子分解的缺陷
  7. 在细节消息中包含能够捕获失败的信息(63)
  8. 期刊投稿状态_这些SCI期刊的投稿显示状态是什么意思?
  9. pytorch框架快速测试你的模型结构是否存在问题并得到输出形状
  10. access子窗体的控件vba怎么写_第37讲:VBA代码中运行错误的处理方式
  11. 利用Python进行百度文库内容爬取(一)
  12. 数据仓库模型数据仓库四大模型
  13. 微信开放平台与微信公众平台的支付关系
  14. 【汇编作业记录Proteus8+keil5 作业 2】
  15. C语言项目(四)——基于Linux系统下的带有GUI界面的即时通信软件
  16. [转载]深入理解Android系统网络架构
  17. 软连接和硬连接(Linux创建软连接一定要用绝对路径)
  18. 「雕爷学编程」Arduino动手做(23)——矩形脉冲发生器
  19. 计算机网络协议——墙都不服,就服你系列
  20. C语言中void的错误用法

热门文章

  1. 下载 Eclipse 免安装版~
  2. 要理解SDH,MSTP,OTN和PTN之间的关系?看看这篇就够了
  3. UE4-Dragon IK 插件的相关调试
  4. 一、ICESat-2数据查询,下载,与处理
  5. 配置typora图片上传服务器
  6. MSTSC连接不到的问题
  7. P5724 【深基4.习5】求极差 / 最大跨度值
  8. UGUI血条渐渐减掉实现
  9. RhythmBox使用体验
  10. 通过autorun.inf和autorun.ico设置U盘识别图标