题目链接
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. 如何用Neo4j和Scikit-Learn做机器学习任务?| 附超详细分步教程
  2. 【win32汇编】0x01 开篇一些乱七八糟的话
  3. Web应用虚拟目录的映射的几种方式
  4. mysql rrd_关于cactiEZ数据迁移操作思路
  5. 非公平锁和公平锁在reetrantlock里的实现过程是怎样的
  6. (前端)html与css,css 4 、继承性和层叠性
  7. 外围功能电路控制 LET′S TRY“嵌入式编程”: 4 of 6
  8. Android中SimpleAdapter的使用—自定义列表
  9. anroid Remote Service 使用注意事项
  10. 人工智能会议等级列表
  11. 表示颜色的英语单词(图)
  12. 转载于 Bob Lyle 谈 DB2 中的 OLAP 函数
  13. 2023年CISSP考点及预约时间参考
  14. 我国亟待建立全国危化品安全监管大数据平台
  15. Unity的C#编程教程_61_委托和事件 Delegates and Events 详解及应用练习
  16. linux 在沙盒中运行,Linux容器的细粒度沙盒策略执行方法与流程
  17. 解决飞鸽传书看不到自己想要找的好友
  18. SpringCloud编译报错: jps.track.ap.dependencies
  19. mysql做十亿条数据查询_数据库优化:mysql数据库单机数十亿数据查询设计
  20. 调制解调系列(1) IQ调制(理论推导+工程实现(FM))

热门文章

  1. 无效的 URI: 未能分析主机名。
  2. 错误 hdfs miss block
  3. FPGA触摸按键控制LED——拓展:按下之后LED闪烁,再次按下停止闪烁
  4. 数据库系统概论学习一
  5. 寻找数组中最接近目标的数字,Java实现
  6. hive 批量执行sql脚本文件 跳过异常语句
  7. 百度搜索引擎使用技巧
  8. Python 对称加密ECB简单实现
  9. 咕咕数据 A 股实时行情数据
  10. 第二届微软CRM中国群线下峰会