Chinaunix首页 | 论坛 | 博客
  • 博客访问: 39393
  • 博文数量: 22
  • 博客积分: 1130
  • 博客等级: 少尉
  • 技术积分: 280
  • 用 户 组: 普通用户
  • 注册时间: 2006-10-11 17:20
文章分类

全部博文(22)

文章存档

2010年(3)

2009年(19)

我的朋友
最近访客

分类:

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;
}


阅读(319) | 评论(0) | 转发(0) |
0

上一篇:POJ 1788

下一篇:POJ 1787

给主人留下些什么吧!~~