class Solution {
public:
int calPoints(vector<string>& ops) {
stack<int> ST;
int sum = ;
for (auto o : ops)
{
if (o == "C")
{
int n = ST.top();
sum -= n;
ST.pop();
}
else if (o == "D")
{
int n = ST.top() * ;
sum += n;
ST.push(n);
}
else if (o == "+")
{
int t1 = ST.top();
ST.pop();
int t2 = ST.top();
int n = t1 + t2;
sum += n;
ST.push(t1);
ST.push(n);
}
else
{
int n = atoi(o.c_str());
sum += n;
ST.push(n);
}
}
return sum;
}
};

leetcode682的更多相关文章

  1. [Swift]LeetCode682. 棒球比赛 | Baseball Game

    You're now a baseball game point recorder. Given a list of strings, each string can be one of the 4 ...

  2. (string stoi 栈)leetcode682. Baseball Game

    You're now a baseball game point recorder. Given a list of strings, each string can be one of the 4 ...

  3. Leetcode682.Baseball Game棒球比赛

    你现在是棒球比赛记录员. 给定一个字符串列表,每个字符串可以是以下四种类型之一: 1.整数(一轮的得分):直接表示您在本轮中获得的积分数. 2. "+"(一轮的得分):表示本轮获得 ...

  4. LeetCode682 棒球比赛

    题目描述: 你现在是棒球比赛记录员.给定一个字符串列表,每个字符串可以是以下四种类型之一:1.整数(一轮的得分):直接表示您在本轮中获得的积分数.2. "+"(一轮的得分):表示本 ...

  5. LeetCode-Stack-Easy

    简单题 1. 有效的括号(leetcode-20) 给定一个只包括 '(',')','{','}','[',']' 的字符串,判断字符串是否有效. 有效字符串需满足: 1. 左括号必须用相同类型的右括 ...

随机推荐

  1. chm下载地址收集

    Js_chm   http://jjidc.jb51.net:81/201007/books/W3C_javascript.rar jQuery_1.7_chm    http://jjidc.jb5 ...

  2. Struts01---入门小案例

    创建web项目    实现的效果! 用户点击页面不同的链接,后台调用不同的代码! 创建两个类实现共同的接口! public interface Action { String execute(); } ...

  3. Agilent RF fundamentals (11)-Vector modulator

     Vector modulator 矢量调制器:调整信号的幅度和相位 http://www.21ic.com/app/test/201805/762401.htm

  4. Django -- DRF 认证流程

    Django Restful Framework (DRF)中类的调用与自定义-- 以 autentication 认证为例 DRF 的 request 对 django 的 request 进行了更 ...

  5. QA,敢问路在何方?听听微软资深QA怎么说~

    转载地址:http://blog.csdn.net/ocean1ee/article/details/8905031 我已经从事测试工作超过7年,从测试员(SDET)成长为高级测试员(SDET II) ...

  6. zoj-3963 Heap Partition(贪心+二分+树状数组)

    题目链接: Heap Partition Time Limit: 2 Seconds      Memory Limit: 65536 KB      Special Judge A sequence ...

  7. Leetcode 1019. Next Greater Node In Linked List

    单调栈的应用. class Solution: def nextLargerNodes(self, head: ListNode) -> List[int]: stack = [] ret = ...

  8. Go语言的序列化与反序列化(gob)

    encoding/gob包实现了高效的序列化,特别是数据结构较复杂的,结构体.数组和切片都被支持. 实现代码如下://定义一个结构体type Student struct { Name string ...

  9. HDU - 6201:transaction transaction transaction(最长路)

    Kelukin is a businessman. Every day, he travels around cities to do some business. On August 17th, i ...

  10. 【java规则引擎】基本语法和相关属性介绍

    一个规则的语法信息 [1]条件部分(LSH部分)===>规则pattern之间的连接条件符号:   (1)LHS 部分是由一个或多个条件组成,条件又称之为 pattern(匹配模式),多个 pa ...