程序代码:
#include <stdio.h> #include <string.h> void pk_bm(char *bm) { char *s ="34567890JQKA2S"; for (int i=0; s[i]; ++i) bm[s[i]] = i+'A'; } char *pk2bm(char *bm, char *in, char *out) { int i; for (i=0; in[i]; ++i) out[i] = bm[in[i]]; out[i] = '\0'; return out; } int main() { char bm[128]= {0}; pk_bm(bm); char pks[8][4]= {"234","589","523","KS2","K2Q","2KS","J98","0KA"}; char *ps[8],*pt; for (int i=0; i<8; ++i) ps[i] = pks[i]; char sm[4]= {0},dm[4]= {0}; for (int i=0; i<7; ++i) for (int j=i+1; j<8; ++j) if (strcmp(pk2bm(bm,ps[i],sm),pk2bm(bm,ps[j],dm))==1) { pt = ps[i]; ps[i] = ps[j]; ps[j] = pt; } printf("\n %s",ps[0]); for (int i=1; i<8; ++i) printf(" < %s",ps[i]); return 0; }
[此贴子已经被作者于2021-12-16 20:00编辑过]