TOJ-2191-Golden Flower

//简单题:竟然和自己平常玩的扎金花规则不同,没看仔细,结果亏了几次WA
#include <iostream>
#include <string>
#include <cstring>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;

char s[6][5];
int flag1, flag2, ans;

struct card
{
	char item;
	int value;
} a[5], b[5], c[5];

bool cmp(card x, card y)
{
	return x.value > y.value || (x.value == y.value && x.item > y.item);
}

int getnum(char c)
{
	if (c >= '2' && c <= '9') return c - '0';
	if (c == 'X') return 10;
	if (c == 'J') return 11;
	if (c == 'Q') return 12;
	if (c == 'K') return 13;
	if (c == 'A') return 14; 
}

int make(card *c)
{
	int d;
	if (c[0].value == c[1].value && c[0].value == c[2].value) d = 6;
	else if (c[0].value == c[1].value + 1 && c[1].value == c[2].value + 1 && c[0].item == c[1].item && c[0].item == c[2].item) d = 5;
	else if (c[0].item == c[1].item && c[0].item == c[2].item) d = 4;
	else if (c[0].value == c[1].value + 1 && c[1].value == c[2].value + 1) d = 3;
	else if (c[0].value == c[1].value || c[0].value == c[2].value || c[2].value == c[1].value) d = 2;
	else d = 1;
	return d;
}

void judge(int x, int y)
{
	if (x > y)  ans = 1;
	else if (x < y) ans = 2;
	else ans = 0;
}

void rejudge(card *a, card *b)
{
	judge(a[0].value, b[0].value);
	if (ans == 0)
	{
		judge(a[1].value, b[1].value);
		if (ans == 0)  judge(a[2].value, b[2].value);
	}
}

int main()
{
	
	while (scanf("%s%s%s%s%s%s", s[0], s[1], s[2], s[3], s[4], s[5]) != EOF)
	{
		for (int i = 0; i < 6; i++)
		{
			if (strlen(s[i]) == 3)
				s[i][1] = 'X';
		}
		for (int i = 0; i < 3; i++)
		{
			a[i].item = s[i][0]; a[i].value = getnum(s[i][1]);
			b[i].item = s[i + 3][0]; b[i].value = getnum(s[i + 3][1]);
		}
		sort(a, a + 3, cmp); sort(b, b + 3, cmp);
		flag1 = make(a); flag2 = make(b);
		if (flag1 > flag2)  ans = 1;
		else if (flag1 < flag2) ans = 2;
		else
		{
			if (flag1 == 6)  judge(a[0].value, b[0].value);
			else if (flag1 == 5)  judge(a[0].value, b[0].value);
			else if (flag1 == 4)  rejudge(a, b);
			else if (flag1 == 3)  judge(a[0].value, b[0].value);
			else if (flag1 == 1)  rejudge(a, b);
			else  rejudge(a, b);
		}
		if (ans == 1)  printf("Win\n");
		else if (ans == 2)  printf("Lose\n");
		else printf("Tie\n");
		memset(s, 0, sizeof(s));
	}
	return 0;
} 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值