题意:给定牌的顺序,然后依次摸牌,最后对每个人的手牌排序输出。

View Code
 1 #include<cstdio>
 2 #include<cstring>
 3 #include<algorithm>
 4 using namespace std;
 5 int po[4][14],mp[300];
 6 char getch[500];
 7 void print_1(int a[])
 8 {
 9     for(int i=0;i<13;i++)
10         printf("|%c %c",getch[a[i]%100],getch[a[i]%100]);
11     printf("|\n");
12 }
13 void print_2(int a[])
14 {
15     for(int i=0;i<13;i++)
16         printf("| %c ",getch[a[i]/100*100]);
17     printf("|\n");
18 }
19 char ss[4][20]={"East player:","South player:","West player:","North player:"};
20 int main()
21 {
22     char s[70];
23     char f[2];
24     mp['C']=100,mp['D']=200,mp['S']=300,mp['H']=400;
25     getch[100]='C',getch[200]='D',getch[300]='S',getch[400]='H';
26     for(int i=2;i<=9;i++)
27         mp[i+'0']=i,getch[i]=i+'0';
28     mp['T']=10,mp['J']=11,mp['Q']=12,mp['K']=13,mp['A']=14;
29     getch[10]='T',getch[11]='J',getch[12]='Q',getch[13]='K',getch[14]='A';
30     bool first=true;
31     while(scanf("%s",f),f[0]!='#')
32     {
33         if(first)
34             first=false;
35         else
36             printf("\n");
37         getchar();
38         gets(s);
39         int pos;
40         if(f[0]=='N')
41             pos=0;
42         else if(f[0]=='E')
43             pos=1;
44         else if(f[0]=='S')
45             pos=2;
46         else
47             pos=3;
48         for(int i=0;i<26;i++)
49         {
50             po[(pos+i)%4][i/4]=mp[s[i*2]]+mp[s[i*2+1]];
51         }
52         gets(s);
53         for(int i=26;i<52;i++)
54         {
55             po[(pos+i)%4][i/4]=mp[s[(i-26)*2]]+mp[s[(i-26)*2+1]];
56         }
57         for(int i=0;i<4;i++)
58             sort(po[i],po[i]+13);
59         for(int i=1;i<=4;i++)
60         {
61             printf("%s\n",ss[i%4]);
62             printf("+---+---+---+---+---+---+---+---+---+---+---+---+---+\n");
63             print_1(po[i%4]);
64             print_2(po[i%4]);
65             print_1(po[i%4]);
66             printf("+---+---+---+---+---+---+---+---+---+---+---+---+---+\n");
67         }
68     }
69     return 0;
70 }