-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path227.cpp
More file actions
37 lines (35 loc) · 739 Bytes
/
227.cpp
File metadata and controls
37 lines (35 loc) · 739 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
//
// 227.cpp
// leetcode
//
// Created by R Z on 2018/7/22.
// Copyright © 2018年 R Z. All rights reserved.
//
#include <stdio.h>
#include <sstream>
#include <string>
using namespace std;
class Solution {
public:
int calculate(string s) {
istringstream is('+'+s+'+');
int total=0, term=0, n;
char op;
while(is>>op){
if(op=='+' || op=='-'){
total+=term;
is>>term;
term*=44-op;
}else{
if(op=='*'){
is>>n;
term *=n;
}else{
is>>n;
term /=n;
}
}
}
return total;
}
};