UVa 340 Master-Mind Hints

UVa 340 Master-Mind Hints

E文不够好,题目意思没有看明白。看了别人题解上讲述的题目大意加上样例分析,大致理解了。
题目意思是这样的,给出两个序列A、B,对于A[i]==B[j],如果i==j,那么这是一个strong对,否则这是一个weak对。题目要求先找出所有的strong对,然后找出weak对(一对数字只能用一次)。
这样的模拟题还是不能急,心里要对过程很明白,一步一步来,不要怕代码长。

以下是我的代码:
#include < cstdio >
#include
< cstring >
using   namespace  std;
const   int  kMaxn( 1007 );

int  main()
{
    
/*
    freopen("data.in","r",stdin);
    freopen("data.out","w",stdout);
    //
*/

    
int  T( 0 ),n;
    
while (scanf( " %d " , & n) == 1   &&  n)
    {
        
int  code[kMaxn];
        
for ( int  i = 1 ;i <= n;i ++ )
            scanf(
" %d " , & code[i]);
        T
++ ;
        printf(
" Game %d:\n " ,T);
        
int  guess[kMaxn];
        
for ( int  i = 1 ;i <= n;i ++ )
            scanf(
" %d " , & guess[i]);
        
while (guess[ 1 ])
        {
            
int  t[kMaxn];
            memcpy(t,code,kMaxn
* sizeof ( int ));
            
int  strong( 0 ),weak( 0 );
            
for ( int  i = 1 ;i <= n;i ++ )
                
if (t[i] == guess[i])
                {
                    strong
++ ;
                    t[i]
= guess[i] = 0 ;
                }
            
for ( int  i = 1 ;i <= n;i ++ )
            {
                
if ( ! t[i])
                    
continue ;
                
for ( int  j = 1 ;j <= n;j ++ )
                    
if (t[i] == guess[j])
                    {
                        weak
++ ;
                        t[i]
= guess[j] = 0 ;
                        
break ;
                    }
            }

            printf(
"     (%d,%d)\n " ,strong,weak);

            
for ( int  i = 1 ;i <= n;i ++ )
                scanf(
" %d " , & guess[i]);
        }
    }

    
return   0 ;
}

你可能感兴趣的:(UVa 340 Master-Mind Hints)