POJ 1013 Counterfeit Dollar

 

做题一定要仔细,要调试一下,看看是不是与自己的想法一致。。。

wa了半天才发现是个地方马虎了。。

# include<stdio.h>
#
include<stdlib.h>
#
include<string.h>
int main()
{
    int n
,  i ,  j ,  k ,   max ,   min ,  max_num ,  min_num ,  real[ 12 ] ,  lh[ 12 ];
    char a[
3 ][ 3 ][ 15 ];
    scanf(
" %d " ,   & n);
    
while (n -- )
    {
        memset(real
,   0 ,   sizeof (real));
        memset(lh
,   0 ,   sizeof (lh));
        
for (i = 0 ; i < 3 ; i ++ )
        {
            
for (j = 0 ; j < 3 ; j ++ )
            {
                scanf(
" %s " ,  a[i][j]);
            }
        }
        
for (i = 0 ; i < 3 ; i ++ )
        {
            
if (a[i][ 2 ][ 0 ==   ' e ' )
            {
                
for (j = 0 ; j < 2 ; j ++ )
                {
                    
for (k = 0 ; ; k ++ )
                    {
                        
if (a[i][j][k]  ==   0 )
                            
break ;
                        real[a[i][j][k]
- 65 =   1 ;
                    }
                }
            }
            
if (a[i][ 2 ][ 0 ==   ' d ' )
            {
                
for (k = 0 ; ; k ++ )
                {
                    
if (a[i][ 0 ][k]  ==   0 )
                        
break ;
                    lh[a[i][
0 ][k] - 65 ] -- ;
                }
                
for (k = 0 ; ; k ++ )
                {
                    
if (a[i][ 1 ][k]  ==   0 )
                        
break ;
                    lh[a[i][
1 ][k] - 65 ] ++ ;
                }
            }
            
if (a[i][ 2 ][ 0 ==   ' u ' )
            {
                
for (k = 0 ; ; k ++ )
                {
                    
if (a[i][ 0 ][k]  ==   0 )
                        
break ;
                    lh[a[i][
0 ][k] - 65 ] ++ ;
                }
                
for (k = 0 ; ; k ++ )
                {
                    
if (a[i][ 1 ][k]  ==   0 )
                        
break ;
                    lh[a[i][
1 ][k] - 65 ] -- ;
                }
            }
        }
        
for (i = 0 ; i < 12 ; i ++ )
        {
            
if (real[i]  ==   1 )
                lh[i] 
=   0 ;
        }
        
max   =  lh[ 0 ];
        max_num 
=   0 ;
        
min   =  lh[ 0 ];
        min_num 
=   0 ;
        
for (i = 1 ; i < 12 ; i ++ )
        {
            
if (lh[i]  >   max )
            {
                
max   =  lh[i];
                max_num 
=  i;
            }
            
if (lh[i]  <   min )
            {
                
min   =  lh[i];
                min_num 
=  i;
            }
        }
        
if ( min   <   0 )
            
min   =   abs ( min );
        
if ( min   >   max )
            
printf ( " %c is the counterfeit coin and it is light./n " ,  min_num + 65 );
        
if ( max   >   min )
            
printf ( " %c is the counterfeit coin and it is heavy./n " ,  max_num + 65 );
    }
}
 
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值