-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path201903-2_1.cpp
68 lines (64 loc) · 1.4 KB
/
201903-2_1.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
#include "stdio.h"
#include "string"
#include "iostream"
#include "queue"
int main() {
int n;
std::string str;
std::queue<int> number;
std::queue<char> op;
char op_temp;
int a, b;
int c;
scanf("%d", &n);
for (int i = 0; i < n; ++i) {
std::cin >> str;
int sum = 0;
for (int j = 0; j < str.size(); ++j) {
if (str[j] > '0' && str[j] <= '9') {
number.push(str[j] - '0');
} else if (str[j] == 'x') {
number.back() *= (str[++j] - '0');
} else if (str[j] == '/') {
number.back() /= (str[++j] - '0');
} else if (str[j] == '+' || str[j] == '-') {
op.push(str[j]);
}
}
while (!op.empty()) {
a = number.front();
number.pop();
op_temp = op.front();
op.pop();
if (op_temp == '+') {
number.front() = a + number.front();
} else if (op_temp == '-') {
number.front() = a - number.front();
}
}
sum = number.front();
number.pop();
if (sum == 24) {
printf("Yes");
} else {
printf("No");
}
if (i < n - 1) {
printf("\n");
}
}
return 0;
}
/*
10
9+3+4x3
5+4x5x5
7-9-9+8
5x6/5x4
3+5+7+9
1x1+9-9
1x9-5/9
8/5+6x9
6x7-3x6
6x4+4/5
*/