Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

Re:(附c代码)

Posted by yanhaofeng at 2006-05-05 10:57:15 on Problem 1786
In Reply To:请教一下大牛门 我的为什么老是报pe 帮忙看看 谢谢(附c代码) Posted by:yanhaofeng at 2006-05-05 10:56:49
#include<stdio.h>
#include<string.h>
int main()
{ int i,j,k,L,a[200],col[100];
  char ch[100],st1[100],st2[100];
  char e[100][100],n[100][100],w[100][100],s[100][100];
  while(1)
  { scanf("%s",ch);if(ch[0]=='#')break;
    scanf("%s%s",st1,st2);
    strcat(st1,st2);//printf("%s\n",st1);
    //st1=st1+st2;
    L=strlen(st1);//printf("%d\n",L);
    for(i='2';i<='9';i++)a[i]=i-'0';
    a['T']=10;a['J']=11;a['Q']=12;
    a['K']=13;a['A']=14;
    col['C']=1;col['D']=2;col['S']=3;col['H']=4;
    //printf("%d\n",a['T']);
    //printf("330\n");
    if(ch[0]=='N')
    { 
      for(i=0,j=0;i<L;i+=8,j++)
      { e[j][0]=st1[i];e[j][1]=st1[i+1];e[j][2]='\0';
        s[j][0]=st1[i+2];s[j][1]=st1[i+3];s[j][2]='\0';
        w[j][0]=st1[i+4];w[j][1]=st1[i+5];w[j][2]='\0';
        n[j][0]=st1[i+6];n[j][1]=st1[i+7];n[j][2]='\0';
      }
      
    }
    
    if(ch[0]=='E')
    { for(i=0,j=0;i<L;i+=8,j++)
      { s[j][0]=st1[i];s[j][1]=st1[i+1];s[j][2]='\0';
        w[j][0]=st1[i+2];w[j][1]=st1[i+3];w[j][2]='\0';
        n[j][0]=st1[i+4];n[j][1]=st1[i+5];n[j][2]='\0';
        e[j][0]=st1[i+6];e[j][1]=st1[i+7];e[j][2]='\0';
      }
    }
    if(ch[0]=='S')
    { for(i=0,j=0;i<L;i+=8,j++)
      { w[j][0]=st1[i];w[j][1]=st1[i+1];w[j][2]='\0';
        n[j][0]=st1[i+2];n[j][1]=st1[i+3];n[j][2]='\0';
        e[j][0]=st1[i+4];e[j][1]=st1[i+5];e[j][2]='\0';
        s[j][0]=st1[i+6];s[j][1]=st1[i+7];s[j][2]='\0';
      }
    }
    if(ch[0]=='W')
    { for(i=0,j=0;i<L;i+=8,j++)
      { n[j][0]=st1[i];n[j][1]=st1[i+1];n[j][2]='\0';
        e[j][0]=st1[i+2];e[j][1]=st1[i+3];e[j][2]='\0';
        s[j][0]=st1[i+4];s[j][1]=st1[i+5];s[j][2]='\0';
        w[j][0]=st1[i+6];w[j][1]=st1[i+7];w[j][2]='\0';
      }
    }//printf("%d\n",j);
    for(i=0;i<j-1;i++)
    { for(k=i+1;k<j;k++)
      { if(col[e[i][0]]>col[e[k][0]])
        { strcpy(st2,e[i]);strcpy(e[i],e[k]);strcpy(e[k],st2);
        }
        if(col[w[i][0]]>col[w[k][0]])
        { strcpy(st2,w[i]);strcpy(w[i],w[k]);strcpy(w[k],st2);
        }
        if(col[n[i][0]]>col[n[k][0]])
        { strcpy(st2,n[i]);strcpy(n[i],n[k]);strcpy(n[k],st2);
        }
        if(col[s[i][0]]>col[s[k][0]])
        { strcpy(st2,s[i]);strcpy(s[i],s[k]);strcpy(s[k],st2);
        }
      }
    }
    for(i=0;i<j-1;i++)
    { for(k=i+1;k<j;k++)
      { if(e[i][0]==e[k][0]&&a[e[i][1]]>a[e[k][1]])
        { strcpy(st2,e[i]);strcpy(e[i],e[k]);strcpy(e[k],st2);
        }
        if(s[i][0]==s[k][0]&&a[s[i][1]]>a[s[k][1]])
        { strcpy(st2,s[i]);strcpy(s[i],s[k]);strcpy(s[k],st2);
        }
        if(n[i][0]==n[k][0]&&a[n[i][1]]>a[n[k][1]])
        { strcpy(st2,n[i]);strcpy(n[i],n[k]);strcpy(n[k],st2);
        }
        if(w[i][0]==w[k][0]&&a[w[i][1]]>a[w[k][1]])
        { strcpy(st2,w[i]);strcpy(w[i],w[k]);strcpy(w[k],st2);
        }
      }
    }
    /*for(i=0;i<j;i++)printf("%s ",e[i]);printf("\n");
   for(i=0;i<j;i++)printf("%s ",s[i]);printf("\n");
    for(i=0;i<j;i++)printf("%s ",w[i]);printf("\n");
    for(i=0;i<j;i++)printf("%s ",n[i]);printf("\n");*/
    printf("South player:\n");
    printf("+---+---+---+---+---+---+---+---+---+---+---+---+---+\n");
    for(i=0;i<j;i++)printf("|%c %c",s[i][1],s[i][1]);printf("|\n");
    for(i=0;i<j;i++)printf("| %c ",s[i][0]);printf("|\n");
    for(i=0;i<j;i++)printf("|%c %c",s[i][1],s[i][1]);printf("|\n");
    printf("+---+---+---+---+---+---+---+---+---+---+---+---+---+\n");
    printf("West player:\n");
    printf("+---+---+---+---+---+---+---+---+---+---+---+---+---+\n");
    for(i=0;i<j;i++)printf("|%c %c",w[i][1],w[i][1]);printf("|\n");
    for(i=0;i<j;i++)printf("| %c ",w[i][0]);printf("|\n");
    for(i=0;i<j;i++)printf("|%c %c",w[i][1],w[i][1]);printf("|\n");
    printf("+---+---+---+---+---+---+---+---+---+---+---+---+---+\n");
    printf("North player:\n");
    printf("+---+---+---+---+---+---+---+---+---+---+---+---+---+\n");
    for(i=0;i<j;i++)printf("|%c %c",n[i][1],n[i][1]);printf("|\n");
    for(i=0;i<j;i++)printf("| %c ",n[i][0]);printf("|\n");
    for(i=0;i<j;i++)printf("|%c %c",n[i][1],n[i][1]);printf("|\n");
    printf("+---+---+---+---+---+---+---+---+---+---+---+---+---+\n");
    printf("East player:\n");
    printf("+---+---+---+---+---+---+---+---+---+---+---+---+---+\n");
    for(i=0;i<j;i++)printf("|%c %c",e[i][1],e[i][1]);printf("|\n");
    for(i=0;i<j;i++)printf("| %c ",e[i][0]);printf("|\n");
    for(i=0;i<j;i++)printf("|%c %c",e[i][1],e[i][1]);printf("|\n");
    printf("+---+---+---+---+---+---+---+---+---+---+---+---+---+\n");
  }
}
/*
N
CQDTC4D8S7HTDAH7D2S3D6C6S6D9S4SAD7H2CKH5D3CTS8C9H3C3
DQS9SQDJH8HAS2SKD4H4S5C7SJC8DKC5C2CAHQCJSTH6HKH9D5HJ
#


Sample Outputa


South player:
+---+---+---+---+---+---+---+---+---+---+---+---+---+
|3 3|5 5|7 7|T T|J J|9 9|T T|J J|3 3|K K|2 2|9 9|T T|
| C | C | C | C | C | D | D | D | S | S | H | H | H |
|3 3|5 5|7 7|T T|J J|9 9|T T|J J|3 3|K K|2 2|9 9|T T|
+---+---+---+---+---+---+---+---+---+---+---+---+---+
West player:
+---+---+---+---+---+---+---+---+---+---+---+---+---+
|2 2|4 4|K K|4 4|5 5|6 6|Q Q|A A|4 4|8 8|T T|J J|8 8|
| C | C | C | D | D | D | D | D | S | S | S | S | H |
|2 2|4 4|K K|4 4|5 5|6 6|Q Q|A A|4 4|8 8|T T|J J|8 8|
+---+---+---+---+---+---+---+---+---+---+---+---+---+
North player:
+---+---+---+---+---+---+---+---+---+---+---+---+---+
|6 6|8 8|9 9|A A|8 8|9 9|A A|4 4|5 5|6 6|7 7|J J|A A|
| C | C | C | C | D | S | S | H | H | H | H | H | H |
|6 6|8 8|9 9|A A|8 8|9 9|A A|4 4|5 5|6 6|7 7|J J|A A|
+---+---+---+---+---+---+---+---+---+---+---+---+---+
East player:
+---+---+---+---+---+---+---+---+---+---+---+---+---+
|Q Q|2 2|3 3|7 7|K K|2 2|5 5|6 6|7 7|Q Q|3 3|Q Q|K K|
| C | D | D | D | D | S | S | S | S | S | H | H | H |
|Q Q|2 2|3 3|7 7|K K|2 2|5 5|6 6|7 7|Q Q|3 3|Q Q|K K|
+---+---+---+---+---+---+---+---+---+---+---+---+---+


Source


*/

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator