已撤销
chenyukang
全部博文(22)
杂(0)
图论(1)
Dp(1)
排序(6)
数学(4)
并查集(3)
2010年(3)
2009年(19)
chunlove
fengergz
分类:
2009-11-02 23:42:09
#include <iostream> using namespace std; const int NUM=4; const int N_Cards=13; typedef struct _Cards { char color; char n; }Card; Card car[NUM][N_Cards]; int IN[NUM]; char Color[5]="CDST"; char NumRank[14]="23456789TJQKA"; int GetRankColor(char c) { for(int i=0;i<5;i++) if(Color[i]==c) return i; } int GetRankNum(char n) { for(int i=0;i<13;i++) if(NumRank[i]==n) return i; } int cmp(const void* a,const void* b) { Card* pa=(Card*)a; Card* pb=(Card*)b; if(pa->color!=pb->color) return GetRankColor(pa->color)-GetRankColor(pb->color); else if(pa->n!=pb->n) return GetRankNum(pa->n)-GetRankNum(pb->n); } void Process() { for(int i=0;i<4;i++) qsort(car[i],N_Cards,sizeof(Card),cmp); } void PrintLine() { cout<<"+---+---+---+---+---+---+---+---+---+---+---+---+---+"<<endl; } void PrintCards(int PN) { for(int i=0;i<13;i++) cout<<"|"<<car[PN][i].n<<" "<<car[PN][i].n; cout<<"|"<<endl; } void PrintColor(int PN) { for(int i=0;i<13;i++) cout<<"| "<<car[PN][i].color<<" "; cout<<"|"<<endl; } void PrintPlayer(int PN) { PrintLine(); PrintCards(PN); PrintColor(PN); PrintCards(PN); PrintLine(); } void PrintOut() { cout<<"South player:"<<endl; PrintPlayer(0); cout<<"West player:"<<endl; PrintPlayer(1); cout<<"North player:"<<endl; PrintPlayer(2); cout<<"East player:"<<endl; PrintPlayer(3); cout<<endl; } int begin; char Co,Num; char c; int main() { do { c=getchar(); if(c=='#') break; else { switch(c) { case 'S': begin=0;break; case 'W': begin=1;break; case 'N': begin=2;break; case 'E': begin=3;break; default: break; } } memset(IN,0,sizeof(IN)); getchar(); for(int i=0;i<26;i++){ scanf("%c%c",&Co,&Num); begin=(begin+1)%4; car[begin][IN[begin]].color=Co; car[begin][IN[begin]].n=Num; IN[begin]++; } getchar(); for(int i=0;i<26;i++){ scanf("%c%c",&Co,&Num); begin=(begin+1)%4; car[begin][IN[begin]].color=Co; car[begin][IN[begin]].n=Num; IN[begin]++; } getchar(); Process(); PrintOut(); }while(1); return 0; }
上一篇:POJ 1788
下一篇:POJ 1787
登录 注册