-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path10700 - Camel trading.cpp
70 lines (68 loc) · 1.46 KB
/
10700 - Camel trading.cpp
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main()
{
string s;
int tes;
cin >> tes;
while(tes--)
{
cin >> s;
istringstream res(s);
stack <ll> st;
ll n;
char ch;
res >> n;
string sp = s;
st.push(n);
ll mx = 0;
while(res >> ch)
{
if(ch == '+')
{
ll x = st.top();
st.pop();
res >> n;
st.push(n + x);
}
else
{
res>> n;
st.push(n);
}
}
mx = 1;
while(st.size() > 0)
{
mx *=st.top();
//cout<<st.top()<< endl;
st.pop();
}
istringstream res1(sp);
res1 >> n;
st.push(n);
while(res1 >> ch)
{
if(ch == '*')
{
ll x = st.top();
st.pop();
res1 >> n;
st.push(x * n);
}
else
{
res1 >> n;
st.push(n);
}
}
ll mn = 0;
while(st.size() > 0)
{
mn += st.top();
st.pop();
}
printf("The maximum and minimum are %lld and %lld.\n",mx, mn);
}
}