您好,欢迎访问三七文档
当前位置:首页 > 建筑/环境 > 工程监理 > 扑克牌3张两人比大小-C语言代码
标准文案扑克牌3张两人比大小,C语言代码背景:两个人每人发3张牌(各从一副牌中),每张牌包括花色(红桃(Heart)黑桃(Spade)方块(Diamond)梅花(Club))和大小(从小到大依次是:2-10、J、Q、K、A),谁手上有最大的一张或多张(如果有相同的牌)牌谁获胜。输入:A的3张牌(未排序)和B的3张牌(未排序)。(参见用例)输出:A的3张牌的排序后的输出和B的3张牌的排序后的输出,以及A和B谁获胜。(参见用例)1.DAH2C3↵2.H4H3DJ↵Viewplain1.WinnerisB!↵2.A:H2DAC3↵3.B:H4H3DJ↵Unlimited256M0TestCase3Viewplain1.HACACB↵2.HQCJCQ↵Viewplain1.InputError!↵Unlimited256M0TestCase4标准文案Viewplain1.HACACJ↵2.DADKDK↵Viewplain1.InputError!↵Unlimited256M0TestCase5Viewplain1.SASJSK↵2.SASJSK↵Viewplain1.WinnerisX!↵2.A:SASKSJ↵3.B:SASKSJ↵Unlimited代码#includestdio.hintasc(charp[][3]);intisError(charp1[][3]);voidcompare(charp3[][3],charp4[][3]);intmain(){chara[3][3],b[3][3],c;inti,j,resulta,resultb,result,flag=0;printf(请输入A的扑克牌,扑克牌之间以空格隔开,然后按下回车:\n);for(i=0;i3;i++){for(j=0;j3;j++){c=getchar();if(c!=''&&c!=10)标准文案{if(j==0){if(c=='H'||c=='S'||c=='D'||c=='C'){if(c=='H')c='Z';}else{printf(InputError!\n);return0;}}if(j==1){if(c=='J'||c=='Q'||c=='K'||c=='A'||(c='1'&&c='9')){if(c=='J')c=59;if(c=='Q')c=60;if(c=='K')c=61;if(c=='A')c=62;if(c=='1')flag=1;}else{printf(InputError!\n);return0;}}if(j==2){if(c!='0'){printf(InputError!\n);return0;}else{flag=0;标准文案c=58;a[i][1]=c;break;}}a[i][j]=c;}else{if(flag==1){printf(InputError!\n);return0;}if(j==2)break;j--;}}}printf(请输入B的扑克牌,扑克牌之间以空格隔开,然后按下回车:\n);for(i=0;i3;i++){for(j=0;j3;j++){c=getchar();if(c!=''&&c!=10){if(j==0){if(c=='H'||c=='S'||c=='D'||c=='C'){if(c=='H')c='Z';}else{printf(InputError!\n);return0;}}if(j==1){if(c=='J'||c=='Q'||c=='K'||c=='A'||(c='1'&&c='9'))标准文案{if(c=='J')c=59;if(c=='Q')c=60;if(c=='K')c=61;if(c=='A')c=62;if(c=='1')flag=1;}else{printf(InputError!\n);return0;}}if(j==2){if(c!='0'){printf(InputError!\n);return0;}else{flag=0;c=58;b[i][1]=c;break;}}b[i][j]=c;}else{if(flag==1){printf(InputError!\n);return0;}if(j==2)break;j--;标准文案}}}resulta=asc(a);if(resulta==0)return0;resultb=asc(b);if(resultb==0)return0;result=isError(a);if(result==0)return0;result=isError(b);if(result==0)return0;compare(a,b);for(i=0;i3;i++){a[i][2]='\0';b[i][2]='\0';}printf(A:);for(i=0;i2;i++){if(a[i][1]='2'&&a[i][1]='9'&&a[i][0]!='Z')printf(%s,a[i]);else{if(a[i][0]=='Z'){if(a[i][1]==58){printf(H);printf(10);}if(a[i][1]==59){printf(H);printf(J);}if(a[i][1]==60){printf(H);printf(Q);标准文案}if(a[i][1]==61){printf(H);printf(K);}if(a[i][1]==62){printf(H);printf(A);}if(a[i][1]='2'&&a[i][1]='9'){printf(H);printf(%c,a[i][1]);}}else{if(a[i][1]==58){printf(%c,a[i][0]);printf(10);}if(a[i][1]==59){printf(%c,a[i][0]);printf(J);}if(a[i][1]==60){printf(%c,a[i][0]);printf(Q);}if(a[i][1]==61){printf(%c,a[i][0]);printf(K);}if(a[i][1]==62){printf(%c,a[i][0]);printf(A);}}标准文案}}for(i=2;i3;i++){if(a[i][1]='2'&&a[i][1]='9'&&a[i][0]!='Z')printf(%s,a[i]);else{if(a[i][0]=='Z'){if(a[i][1]==58){printf(H);printf(10);}if(a[i][1]==59){printf(H);printf(J);}if(a[i][1]==60){printf(H);printf(Q);}if(a[i][1]==61){printf(H);printf(K);}if(a[i][1]==62){printf(H);printf(A);}if(a[i][1]='2'&&a[i][1]='9'){printf(H);printf(%c,a[i][1]);}}else{if(a[i][1]==58){标准文案printf(%c,a[i][0]);printf(10);}if(a[i][1]==59){printf(%c,a[i][0]);printf(J);}if(a[i][1]==60){printf(%c,a[i][0]);printf(Q);}if(a[i][1]==61){printf(%c,a[i][0]);printf(K);}if(a[i][1]==62){printf(%c,a[i][0]);printf(A);}}}}printf(\nB:);for(i=0;i2;i++){if(b[i][1]='2'&&b[i][1]='9'&&b[i][0]!='Z')printf(%s,b[i]);else{if(b[i][0]=='Z'){if(b[i][1]==58){printf(H);printf(10);}if(b[i][1]==59){printf(H);printf(J);标准文案}if(b[i][1]==60){printf(H);printf(Q);}if(b[i][1]==61){printf(H);printf(K);}if(b[i][1]==62){printf(H);printf(A);}if(b[i][1]='2'&&b[i][1]='9'){printf(H);printf(%c,b[i][1]);}}else{if(b[i][1]==58){printf(%c,b[i][0]);printf(10);}if(b[i][1]==59){printf(%c,b[i][0]);printf(J);}if(b[i][1]==60){printf(%c,b[i][0]);printf(Q);}if(b[i][1]==61){printf(%c,b[i][0]);printf(K);}if(b[i][1]==62)标准文案{printf(%c,b[i][0]);printf(A);}}}}for(i=2;i3;i++){if(b[i][1]='2'&&b[i][1]='9'&&b[i][0]!='Z')printf(%s,b[i]);else{if(b[i][0]=='Z'){if(b[i][1]==58){printf(H);printf(10);}if(b[i][1]==59){printf(H);printf(J);}if(b[i][1]==60){printf(H);printf(Q);}if(b[i][1]==61){printf(H);printf(K);}if(b[i][1]==62){printf(H);printf(A);}if(b[i][1]='2'&&b[i][1]='9'){printf(H);printf(%c,b[i][1]);标准文案}}else{if(b[i][1]==58){printf(%c,b[i][0]);printf(10);}if(b[i][1]==59){printf(%c,b[i][0]);printf(J);}if(b[i][1]==60){printf(%c,b[i][0]);printf(Q);}if(b[i][1]==61){printf(%c,b[i][0]);printf(K);}if(b[i][1]==62){printf(%c,b[i][0]);printf(A);}}}}printf(\n);return0;}intasc(charp[][3]){intm,temp[2];if(p[0][1]==p[1][1]){if(p[0][0]==p[1][0]){printf(InputError!\n);return0;标准文案}}if(p[1][1]==p[2][1]){if(p[1][0]==p[2][0]){printf(InputError!\n);return0;}}if(p[0][1]==p[2][1]){if(p[0][0]==p[2][0]){printf(InputError!\n);return0;}}m=0;if(p[m][0]p[m+1][0]){temp[0]=p[m][0];temp[1]=p[m][1];p[m][0]=p[m+1][0];p[m][1]=p[m+1][1];p[m+1][0]=temp[0];p[m+1][1]=temp[1];}if(p[m][0]p[m+2][0]){temp[0]=p[m][0];temp[1]=p[m][1];p[m][0]=p[m+2][0];p[m][1]=p[m+2][1];p[m+2][0]=temp[0];p[m+2][1]=temp[1];}m=1;if(p[m][0]p[m+1][0]){temp[0]=p[m][0];temp[1]=p[m][1];p[m][
本文标题:扑克牌3张两人比大小-C语言代码
链接地址:https://www.777doc.com/doc-5977354 .html