成都麻将

来源:互联网 发布:淘宝开店流程图解 编辑:程序博客网 时间:2024/07/24 01:52
#include<iostream>
#include<set>
#include <string>
#include <map>
using namespace std;


class cmp
{
public:
cmp();
bool operator()( string x,string y)
{
if( x[1] == y[1] )
{
return x[0]<y[0];
}
else
return c[ x[1] ] < c[ y[1] ];
}
public:
static map<char,int> c;
};
map<char,int> cmp::c;
cmp::cmp()
{
cmp::c['T'] = 1;
cmp::c['D'] = 2;
cmp::c['W'] = 3;
};


set<string,class cmp> result;
char type[3] = { 'T','D','W'};


void check( int cards[],int num)
{
//当不足3张牌时,判断胡什么牌
if( num < 3)
{
if( num == 1)
{
for( int i = 1 ; i< 30;i++)
{
if( cards[i] == 1 )
{
char p[3] ;
p[2] = '\0';
p[0] = (i % 10) + '0';
p[1] =type[ (i/10)];
result.insert( string(p) );
break;
}
}
}
else if( num == 2)
{
for( int i = 1 ; i< 30;i++)
{
if( cards[i] ==2 )
{
char p[3] ;
p[2] = '\0';
p[0] = (i % 10) + '0';
p[1] =type[ (i/10)];
result.insert( string(p) );
break;
}
if( cards[i] == 1  && cards[i+1] == 1)
{
char p[3] ;
p[2] = '\0';


if(  (i+2) %10  !=  0)
{
p[0] = ((i+2) % 10) + '0';
p[1] =type[ ((i+2) /10)];
result.insert( string(p) );
}


if(  (i-1) %10  !=  0)
{
p[0] = ((i-1) % 10) + '0';
p[1] =type[ ((i-1) /10)];
result.insert( string(p) );
}
break;
}
if( cards[i] == 1  && cards[i+2] == 1)
{
char p[3] ;
p[2] = '\0';
if(  (i+1) % 10 != 0 )
{
p[0] = ((i+1) % 10) + '0';
p[1] =type[ ((i+1) /10)];
result.insert( string(p) );
}
break;
}
}
}
}
//牌多余三张时,提取
for( int i = 1 ; i< 30;i++)
{
//未提取过对子,提取
if( cards[i] >=2 && num%3 == 1)
{
cards[i] -= 2;
check(cards,num-2);
cards[i] += 2;
}
//可以提取三张,提取
if( cards[i] >=3 )
{
cards[i] -= 3;
check(cards,num-3);
cards[i] += 3;
}
if( cards[i] >=1 &&  cards[i +1] >=1 && cards[i+2] >=1 )
{
cards[i] -= 1;
cards[i+1] -= 1;
cards[i+2] -= 1;
check(cards,num-3);
cards[i] += 1;
cards[i+1] += 1;
cards[i+2] += 1;
}
}
}








int main()
{
freopen("input.txt","r",stdin);


string majiang;
while( cin>>majiang)
{
result.clear();
int cardInHand[33] = {0};
for( int i = 0; i < 25;i+=2)
{
char p = majiang[i+1];
char q = majiang[i];
switch(  p )
{
case 'T':
cardInHand[  q - '0' ] ++;
break;
case 'D':
cardInHand[ q - '0' +10 ]++;
break;
case 'W':
cardInHand[ q- '0' + 20] ++;
break;
default:
;
}
}
/*for( int i = 0; i< 30; i++)
{
cout<< cardInHand[i]<<endl;
}*/
check( cardInHand ,13);
set<string,cmp>::iterator it = result.begin();
cout<<result.size()<<endl;
for( ;it != result.end() ;it++)
{
cout<< *it;
}
}
return 0;
}
0 0
原创粉丝点击