二十四点
#include<iostream>
#include<cstdio>
#include<string>
#include<stack>
using namespace std
;
stack
<int> s
;
string ss
[101];
int main() {
int n
;
cin
>>n
;
char ch
;
int a
,b
,sum
=0;
for(int i
=0; i
<n
; i
++) {
scanf("%d",&a
);
s
.push(a
);
ch
=getchar();
while(scanf("%d",&a
)) {
if(ch
=='x') {
b
=s
.top();
b
=a
*b
;
s
.pop();
s
.push(b
);
} else if(ch
=='+') {
s
.push(a
);
} else if(ch
=='-') {
s
.push(-a
);
} else if(ch
=='/') {
b
=s
.top();
b
=b
/a
;
s
.pop();
s
.push(b
);
}
ch
=getchar();
if(ch
=='\n')
break;
}
while(!s
.empty()) {
b
=s
.top();
sum
=sum
+b
;
s
.pop();
}
if(sum
==24)
ss
[i
]="Yes";
else
ss
[i
]="No";
sum
= 0;
while (!s
.empty()) {
s
.pop();
}
}
for(int i
=0;i
<n
;i
++)
{
cout
<<ss
[i
]<<endl
;
}
return 0;
}
转载请注明原文地址:https://tech.qufami.com/read-27777.html