用C++或者C写卡牌游戏。

你好

下面这个小程序有点笨(语法很简单)

它分不清一些重复的情况。

但结果基本正确。

# include & ltiostream & gt

使用命名空间std

int main(){

int i1,i2,i3,i4,v,n1,N2;

int num = 0;

int a,b;

double t1,t2,t3,t4,choice[4],s1[4],s2[4][4],s3[2],t;

for(;;){

cout & lt& lt"# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #

cout & lt& lt“请给出你抽中的第一张牌:“;

CIN & gt;& gt选择[0];

cout & lt& lt“请给出你抽的第二张牌:“;

CIN & gt;& gtchoice[1];

cout & lt& lt“请给出你抽中的第三张牌:“;

CIN & gt;& gt选择[2];

cout & lt& lt“请给出你抽中的第四张牌:“;

CIN & gt;& gt选择[3];

cout & lt& lt“# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #思考中\ n”;

for(b = 0;b & lt=2;b++)

for(a = 3;a & gt= 1+b;a - )if(选择[a]& lt;choice[a-1]){

t = choice[a-1];

choice[a-1]= choice[a];

choice[a]= t;}

for(int j = 0;j & lt4;j++)cout & lt;& ltj+1 & lt;& lt". "& lt& ltchoice[j]& lt;& lt" ";

cout & lt& lt”\ n”;

for(I 1 = 0;I 1 & lt;4;i1++){

t 1 = choice[I 1];

for(I2 = 0;i2 & lt4;i2++){ if((i1-1)!= 0 & amp& ampt 1 = = choice[I 1-1])破位;

如果(i2!=i1){

T2 = choice[I2];

s 1[0]= t 1+T2;

s 1[1]= t 1-T2;

s 1[2]= t 1 * T2;

s 1[3]= t 1/T2;

for(i3 = 0;i3 & lt4;i3++){

如果(i3!= I 1 & amp;& ampi3!=i2){

T3 = choice[i3];

for(v = 0;v & lt4;v++)

{ S2[v][0]= s 1[v]+T3;

S2[v][1]= s 1[v]-T3;

S2[v][2]= s 1[v]* T3;

S2[v][3]= s 1[v]/T3;}

for(i4 = 0;i4 & lt4;i4++){

如果(i4!= I 1 & amp;& ampi4!= i2 & amp& ampi4!=i3){

T4 = choice[i4];

for(n 1 = 0;n 1 & lt;4;n 1++)for(N2 = 0;n2 & lt4;n2++)

if(S2[n 1][N2]+T4 = = 24 | | S2[n 1][N2]-T4 = = 24 | | S2[n 1][N2]* T4 = = 24 | | S2[n 1][N2]/T4 = = 24){

cout & lt& lt"找到了一个组合方案:\ n(("

if(s 1[n 1]= = t 1+T2)cout & lt;& lt" + ";

if(s 1[n 1]= = t 1-T2)cout & lt;& lt" - ";

if(s 1[n 1]= = t 1 * T2)cout & lt;& lt" * ";

if(s 1[n 1]= = t 1/T2)cout & lt;& lt" / ";

if(N2 = = 0)cout & lt;& ltt2 & lt& lt”)+”& lt;& ltT3;

if(N2 = = 1)cout & lt;& ltt2 & lt& lt”)“”& lt& ltT3;

if(N2 = = 2)cout & lt;& ltt2 & lt& lt")* " & lt& ltT3;

if(N2 = = 3)cout & lt;& ltt2 & lt& lt”)/“& lt;& ltT3;

if(S2[n 1][N2]+T4 = = 24)cout & lt;& lt”)+”& lt;& ltt4 & lt& lt" = 24 \ n ";

if(S2[n 1][N2]-T4 = = 24)cout & lt;& lt”)“”& lt& ltt4 & lt& lt" = 24 \ n ";

if(S2[n 1][N2]* T4 = = 24)cout & lt;& lt")* " & lt& ltt4 & lt& lt" = 24 \ n ";

if(S2[n 1][N2]/T4 = = 24)cout & lt;& lt”)/“& lt;& ltt4 & lt& lt" = 24 \ n ";

num++;

}

}}}

}}}}

for(I 1 = 0;I 1 & lt;4;i1++){

t 1 = choice[I 1];

for(I2 = 0;i2 & lt4;i2++){

如果(i2!=i1){

T2 = choice[I2];

s 1[0]= t 1 * T2;

s 1[1]= t 1/T2;

for(i3 = 0;i3 & lt4;i3++){

如果(i3!= I 1 & amp;& ampi3!=i2){

T3 = choice[i3];

for(i4 = 0;i4 & lt4;i4++){

如果(i4!= I 1 & amp;& ampi4!= i2 & amp& ampi4!=i3){

T4 = choice[i4];

S3[0]= T3 * T4;

S3[1]= T3/T4;

for(n 1 = 0;n 1 & lt;2;n 1++)for(N2 = 0;n2 & lt2;n2++)

if(s 1[n 1]+S3[N2]= = 24 | | s 1[n 1]-S3[N2]= = 24){

cout & lt& lt"找到一个组合方案:\ n("

if(s 1[n 1]= = t 1 * T2)cout & lt;& lt" * ";

if(s 1[n 1]= = t 1/T2)cout & lt;& lt" / ";

if(s 1[n 1]+S3[N2]= = 24)cout & lt;& ltt2 & lt& lt”)+(“& lt;& ltT3;

if(s 1[n 1]-S3[N2]= = 24)cout & lt;& ltt2 & lt& lt”)-(“& lt;& ltT3;

if(S3[N2]= = T3 * T4)cout & lt;& lt" * " & lt& ltt4 & lt& lt")= 24 \ n ";

if(S3[N2]= = T3/T4)cout & lt;& lt“/”& lt;& ltt4 & lt& lt")= 24 \ n ";

num++;

}

}}}

}}}}

cout & lt& lt“总有* * *”

if(num = = 0)cout & lt;& lt“这四张牌不能形成24分~ ~ ~ \ n”;

num = 0;

}

返回0;

}