水题,统计下重不重复即可
#include <stdio.h>
#include <string.h>
char str[20][10];
char t[50];
int work(int i, int j, int k, int m)
{
int p = 0;
memset(t, 0, sizeof(t));
if (!t[ str[i][m] -'0' ])
{
p++;
t[ str[i][m] -'0' ] = 1;
}
if (!t[ str[j][m] -'0' ])
{
p++;
t[ str[j][m] -'0' ] = 1;
}
if (!t[ str[k][m] - '0' ])
{
p++;
t[ str[k][m] -'0' ] = 1;
}
return p;
}
int main()
{
while ( EOF != scanf("%s", str[0]) )
{
int i, j, k, l, count= 0;
for ( i = 1 ; i < 12 ; i++ )
scanf("%s", str[i]);
printf("CARDS: ");
for ( i = 0 ; i < 12 ; i++ )
printf(" %s", str[i]);
for ( i = 0 ; i < 12 ; i++ )
for ( j = i+1 ; j < 12 ; j++ )
for ( k = j+1 ; k < 12 ; k++ )
{
int p[4];
for ( l = 0 ; l < 4 ; l++ )
{
p[l]= work(i, j ,k, l);
}
if ( ( p[0] == 1 || p[0] == 3 ) && ( p[1] == 1 || p[1] == 3 ) && ( p[2] == 1 || p[2] == 3 ) && ( p[3] == 1 || p[3] == 3 ) )
{
count++;
if ( 1 == count )
printf("\nSETS: 1. %s %s %s\n", str[i], str[j], str[k]);
else printf(" %d. %s %s %s\n", count, str[i], str[j], str[k]);
}
}
if (!count) printf("\nSETS: *** None Found ***\n");
putchar(10);
}
return 0;
}