题意:看了题解才明白题目可能胡的情况,要求让你在所有还能拿的牌中找出可能胡的牌,最简单的胡法是,在有对子的情况下,再找出三张相同的或者顺子
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
const char* mahjong[] = {"1T", "2T", "3T", "4T", "5T", "6T", "7T", "8T", "9T",
"1S", "2S", "3S", "4S", "5S", "6S", "7S", "8S", "9S",
"1W", "2W", "3W", "4W", "5W", "6W", "7W", "8W", "9W",
"DONG", "NAN", "XI", "BEI",
"ZHONG", "FA", "BAI"
}; //指针数组
int c[34];
int convert(char *s)
{
for (int i = 0; i < 34; i++)
if (strcmp(mahjong[i],s) == 0)
return i;
return -1;
}
bool search(int t)
{
for (int i = 0; i < 34; i++)
if (c[i] >= 3)
{
if (t == 3)
return true;
c[i] -= 3;
if (search(t+1))
return true;
c[i] += 3;
}
for (int i = 0; i <= 24; i++)
if (i % 9 <= 6 && c[i] >= 1 && c[i+1] >= 1 && c[i+2] >= 1)
{
if (t == 3)
return true;
c[i]--,c[i+1]--,c[i+2]--;
if (search(t+1))
return true;
c[i]++,c[i+1]++,c[i+2]++;
}
return false;
}
bool check()
{
for (int i = 0; i < 34; i++)
{
if (c[i] >= 2)
{
c[i] -= 2;
if (search(0))
return true;
c[i] += 2;
}
}
return false;
}
int main()
{
int cas = 0;
bool ok;
char s[100];
int majiang[15];
while (scanf("%s",s) != EOF)
{
if (s[0] == '0')
break;
printf("Case %d:",++cas);
majiang[0] = convert(s);
for (int i = 1; i < 13; i++)
{
scanf("%s",s);
majiang[i] = convert(s);
}
ok = false;
for (int i = 0; i < 34; i++)
{
memset(c,0,sizeof(c));
int j;
for (int j = 0; j < 13; j++)
c[majiang[j]]++;
if (c[i] >= 4)
continue;
c[i]++;
if (check())
{
ok = true;
printf(" %s",mahjong[i]);
}
c[i]--;
}
if (!ok)
printf(" Not ready");
printf("\n");
}
return 0;
}