POJ 3080 Blue Jeans

//本题爆搜即可......
//含有一点是要按字典序排序,输出最小值
//程序写得太麻烦了.....

 

code
#include < iostream >
using   namespace  std;

int  sub( char *  a, char *  b, int  n)
{
    
int  i,j;
    
for ( i = 0 ;i <= 60 - n; ++ i)
    {
        
for ( j = 0 ;j < n; ++ j)
            
if (a[j] != b[j + i])
                
break ;
        
if (j == n)
            
return   1 ;
    }

    
return   0 ;
}
// 是否字串
int  main()
{
    
char  a[ 61 ],b[ 15 ][ 61 ],temp[ 61 ],tag[ 100 ];
    
int  i,j,total,n,index,k,t,num,tag1,tag2,tag3;
    cin
>> total;
    
while (total -- )
    {
        cin
>> n;
        cin
>> a;
        
for (i = 0 ;i < n - 1 ; ++ i)
            cin
>> b[i];
        
for (i = 60 ;i > 2 ; -- i)
        {
            index
= 0 ;
            num
= 0 ;
            tag3
= 0 ;
            
for (j = 0 ;j <= 60 - i; ++ j)
            {
                tag1
= 0 ;
                tag2
= 0 ;
                
for (k = 0 ;k < n - 1 ; ++ k)
                {
                    
if (sub( & a[j],b[k],i))
                        ;
                    
else   break ;
                }
                
if (k == n - 1 )
                {
                    tag3
= 1 ; // 有公共
                     if (tag1 == 1 )
                    {
                        tag2
= 0 ;
                        
for (t = 0 ;t < i; ++ t)
                            
if (a[j + t] < temp[t])
                            {
                                tag2
= 1 ;
                                
break ;
                            }
                            
else   if (a[j + t] > temp[t])
                                
break ;
                        
if (tag2 == 1 )
                            
for (t = 0 ;t < i; ++ t)
                                temp[t]
= a[j + t];
                    }
                    
else
                    {
                        tag1
= 1 ;
                        
for (t = 0 ;t < i; ++ t)
                            temp[t]
= a[j + t];
                    }
                }

            }
            
            
if (tag3)
            {
                num
= i;
                i
=- 1 ;
                
break ;
            }
        }
        
if (num == 0 )
            cout
<< " no significant commonalities " ;
        
for (t = 0 ;t < num; ++ t)
            cout
<< temp[t];
        cout
<< endl;

        
    }
                

}

 

 

你可能感兴趣的:(poj)