-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path080.cpp
More file actions
62 lines (60 loc) · 1.29 KB
/
Copy path080.cpp
File metadata and controls
62 lines (60 loc) · 1.29 KB
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
#include <iostream>
#include <string>
using namespace std;
int n, i, r, x, y, z, m=30001,c;
string s, ch, t, b;
int a(int i) {
ch = "";
n = 1;
if (s[i] == '-') {
n = -1;
i++;
}
while (s[i] >= '0' && s[i] <= '9') {
ch += s[i];
i++;
}
r = i;
if (ch != "")
return stoi(ch) * n;
else return m;
}
int main() {
getline(cin, s);
if (s.find(" ") != string::npos) {
cout << "ERROR";
return 0;
}
x = a(0);
if ((x == m) || (s[r] != '+' && s[r] != '-' && s[r] != '*' && s[r] != '/'))
c=1;
else {
t = s[r];
y = a(r + 1);
if ((y == m) || (s[r] != '='))
c = 1;
else {
b = s[r];
z = a(r + 1);
if (z == m || r < s.size())
c = 1;
else {
double l = x;
if (t == "+")
l = x + y;
if (t == "-")
l = x - y;
if (t == "*")
l = x * y;
if (t == "/")
l = double(x) / y;
if (l == z)
cout << "YES";
else cout << "NO";
}
}
}
if (c == 1)
cout << "ERROR";
return 0;
}