#include <iostream> using namespace std; int f(int a,int b,int x) { if(x==1) return a-b; if(x==2) return a+b; if(x==3) return a/b; if(x==4) return a*b; } int main() { // cout << "Hello world!" << endl; int cnt; cin>>cnt; while(cnt--) { int a,b,c,d; int x,y,z; char cc; cin>>a; cin>>cc; // cout<<"cc"<<cc<<endl; if(cc=='x') x=4; else if(cc=='/') x=3; else if(cc=='+') x=2; else x=1; // cout<<x<<endl; cin>>b; cin>>cc; // cout<<"cc"<<cc<<endl; if(cc=='x') y=4; else if(cc=='/') y=3; else if(cc=='+') y=2; else y=1; // cout<<y<<endl; cin>>c; cin>>cc; //cout<<"cc"<<cc<<endl; if(cc=='x') z=4; else if(cc=='/') z=3; else if(cc=='+') z=2; else z=1; // cout<<z<<endl; cin>>d; //cout<<x<<y<<z<<endl; int result=0; if((x==1||x==2)&&(y==1||y==2)&&(z==1||z==2))///a+b+c+d { int result1=f(a,b,x); int result2=f(result1,c,y); result=f(result2,d,z); } if((x==3||x==4)&&(y==3||y==4)&&(z==3||z==4))///a*b*c*d { int result1=f(a,b,x); int result2=f(result1,c,y); result=f(result2,d,z); } if((x==1||x==2)&&(y==1||y==2)&&(z==3||z==4))///a+b+c*d { int result1=f(c,d,z); // cout<<"result1"<<result1<<endl; int result2=f(a,b,x); // cout<<"result2"<<result2<<endl; result=f(result1,result2,y); } if((x==1||x==2)&&(y==3||y==4)&&(z==3||z==4))///a+b*c*d { int result1=f(b,c,y); int result2=f(result1,d,z); result=f(a,result2,x); } if((x==1||x==2)&&(y==3||y==4)&&(z==1||z==2))///a+b*c+d { int result1=f(b,c,y); int result2=f(a,result1,x); result=f(result2,d,z); } if((x==3||x==4)&&(y==1||y==2)&&(z==1||z==2))///a*b+c+d { int result1=f(a,b,x); int result2=f(result1,c,y); result=f(result2,d,z); } if((x==3||x==4)&&(y==3||y==4)&&(z==1||z==2))///a*b*c+d { int result1=f(a,b,x); int result2=f(result1,c,y); result=f(result2,d,z); } if((x==3||x==4)&&(y==1||y==2)&&(z==3||z==4))///a*b+c*d { int result1=f(a,b,x); int result2=f(c,d,z); result=f(result1,result2,y); } // cout<<result<<endl; if(result==24) { cout<<"Yes"<<endl; } else cout<<"No"<<endl; } return 0; }
24点代码
猜你喜欢
转载自blog.csdn.net/zzyzzylalala/article/details/97652249
今日推荐
周排行