akoj-1222-炸金花

炸金花

Time Limit:1000MS  Memory Limit:65536K

Total Submit:40 Accepted:19

Description

 炸金花是一个风靡全球的扑克游戏,喜欢玩他的人不计其数,不少人因为这个游戏发了家,而更多的人则输得倾家荡产。为了帮助赌徒们戒掉它,安徽科技学院决定派你去写一个程序,帮助赌徒们更好的认识这个游戏。 

  炸金花在这里被简化成这样一个情况:每一个人都会被随机的发到1~13中的任意三张牌,然后比较大小。比较大小的方式是这样的: 

  豹子:即三张一样的牌,同类型的豹子,数字大的更大,豹子大于任何其他情况。 

  顺子:即三张递增的连续的牌,比如(4,5,6),(1,2,3),都是顺子的话,谁的点数大则大,顺子大于对子和单张。 

  对子:即两张一样的牌带一张单牌,比如(1,1,4),(2,2,5),都是对子的话,谁的那一对大则大,如果那一对也一样,则比较单张的大小。对子大于单张。 

  单张:即三张牌不是上述的三种。单张的比较大小方式是,先比较最大的,再比较第二大的,再比较第三大的。 

  你的任务是,对于给定的牌,判断输赢

Input

多组输入,每组输入两行,第一行三个数是你的三张牌,第二行是对手的三张牌 

Output

每组数据输出,若你赢输出you win,否则you lose

Sample Input

9 9 9
7 8 9

Sample Output

you win

Source

这个题只需不断的分类,但感觉自己写的这代码量还是有点多了,欢迎大家来此评论

#include 

void my_sort(int *x, int *y, int *z)
{
    int t;
    if ( *x > *y ) { t = *x; *x = *y; *y = t; }
    if ( *x > *z ) { t = *x; *x = *z; *z = t; }
    if ( *y > *z ) { t = *y; *y = *z; *z = t; }
}

int judge_1(int *x, int *y, int *z)
{
    if ( *x == *y && *y == *z )
        return 1;
    return 0;
}

int judge_2(int *x, int *y, int *z)
{
    if ( *y == *x + 1 && *y == *z -1 )
        return 1;
    return 0;
}

int judge_3(int *x, int *y, int *z)
{
    if ( *x == *y )
        return *x;
    else if ( *y == *z ) {
        return *y;
    }
    return 0;
}

int judge_4(int *x, int *y, int *z)
{
    if ( *x == *y )
        return *z;
    else if ( *y == *z ) {
        return *x;
    }
    return 0;
}

void printY()
{
    printf("you win\n");
}

void printN()
{
    printf("you lose\n");
}

int main()
{
    int a, b, c, x, y, z;
    while ( ~scanf("%d%d%d%", &a, &b, &c) )
    {
        scanf("%d%d%d", &x, &y, &z);
        my_sort(&a, &b, &c);
        my_sort(&x, &y, &c);
        if ( judge_1(&a, &b, &c) ) {
            if ( judge_1(&x, &y, &z) ) {
                if ( c > z ) {
                    printY();
                }
                else {
                    printN();
                }
            }
            else {
                printY();
            }
        }
        else if ( judge_2(&a, &b, &c) ) {
            if ( judge_2(&x, &y, &z) ) {
                if ( c > z ) {
                    printY();
                }
                else {
                    printN();
                }
            }
            else {
                printY();
            }
        }
        else if ( judge_3(&a, &b, &c) ) {
            if ( judge_3(&x, &y, &z) ) {
                if ( judge_3(&a, &b, &c) > judge_3(&x, &y, &z) ) {
                    printY();
                }
                else if ( judge_3(&a, &b, &c) < judge_3(&x, &y, &z) ) {
                    printN();
                }
                else if ( judge_4(&a, &b, &c) > judge_4(&x, &y, &z) ) {
                    printY();
                }
                else {
                    printN();
                }
            }
            else {
                printY();
            }
        }
        else  {
            if ( c > z ) {
                printY();
            }
            else if ( c < z ) {
                printN();
            }
            else if ( b > y ) {
                printY();
            }
            else if ( b < y ) {
                printN();
            }
            else if ( a > x ) {
                printY();
            }
            else if ( a < x ) {
                printN();
            }
        }
    }

    return 0;
}
坚持原创技术分享,您的支持将鼓励我继续创作!
  • 本文作者: Fayne
  • 本文链接: 387.html
  • 版权声明: 本博客所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明出处!