You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

68 lines
2.3 KiB

2 years ago
/*/*******************************************************************************
** **
** Jiedi(China nanjing)Ltd. **
** **
*******************************************************************************/
/*****************************FILE INFOMATION***********************************
**
** Project : ---leetcode
** Contact : xiacaojun@qq.com
** : http://blog.csdn.net/jiedichina
** : http://study.163.com/u/xiacaojun
https://jiedi.ke.qq.com/
csdn https://edu.csdn.net/course/detail/25037
** 51cto http://edu.51cto.com/lecturer/index/user_id-100013755.html
** http://www.laoxiaketang.com
**
** ---leetcode 296249312
** : jiedi2007
** :
**
*****************************************************************************
// 算法设计与编程实践---基于leetcode的企业真题库 课程 QQ群296249312 下载代码和交流*/
/*
* @lc app=leetcode.cn id=682 lang=cpp
*
* [682]
*/
#include <vector>
#include <string>
#include <sstream>
using namespace std;
class Solution {
public:
int calPoints(vector<string>& ops) {
vector<int> res;
int sum =0 ;
for(int i=0;i<ops.size();i++){
if(ops[i] !="+" && ops[i] !="C" && ops[i]!="D"){
res.push_back(str2int(ops[i]));
}
else if(ops[i]=="C"){
res.pop_back();
}else if(ops[i] == "D"){
res.push_back(res.back()*2);
}else if(ops[i] =="+"){
res.push_back(res[res.size()-2]+res.back());
}
}
for(int i=0;i<res.size();i++){
sum+=res[i];
}
return sum;
}
int str2int(string s){
stringstream ss;
int n;
ss<<s;
ss>>n;
return n;
}
};