poj 1053 Set Me

水题,统计下重不重复即可
#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, 
0sizeof(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;
}

posted on 2011-08-17 00:46 purplest 阅读(371) 评论(0)  编辑 收藏 引用 所属分类: others


只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理


<2011年8月>
31123456
78910111213
14151617181920
21222324252627
28293031123
45678910

导航

统计

常用链接

留言簿

随笔分类(70)

随笔档案(68)

ACMer

搜索

最新随笔

最新评论