做题一定要仔细,要调试一下,看看是不是与自己的想法一致。。。
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 );
}
}
# 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 );
}
}