嗨~我交了兩份看起來差不多的code上去
可是一個WA一個AC
來請問大家這兩支code的差別在哪@@
WA版:
#include<cstdio>
#include<cstdlib>
#include<cstring>
int judge( char* a, char* b )
{
if( strcmp( a, b ) == 0 )
return 0;
char tmp[ 21 ] = { 0 };
for( int i = 0; a[ i ]; ++a )
if( a[ i ] != ' ' )
tmp[ strlen( tmp ) ] = a[ i ];
return strcmp( tmp, b )? 1 : 2;
}
int main()
{
int t;
char a[ 21 ], b[ 21 ], result[][ 20 ] = { "Yes", "Wrong Answer", "Output Format Error" };
scanf( "%d\n", &t ); // scanf( "%d%*c", &t ) 也會錯
for( int n = 1; n <= t; ++n )
{
gets( a );
gets( b );
printf( "Case %d: %s\n", n, result[ judge( a, b ) ] );
}
}
AC版:
#include<cstdio>
#include<cstdlib>
#include<cstring>
int judge( char* a, char* b )
{
if( strcmp( a, b ) == 0 )
return 0;
char tmp[ 21 ] = { 0 };
for( int i = 0; a[ i ]; ++a )
if( a[ i ] != ' ' )
tmp[ strlen( tmp ) ] = a[ i ];
return strcmp( tmp, b )? 1 : 2;
}
int main()
{
int t;
char a[ 21 ], b[ 21 ], result[][ 20 ] = { "Yes", "Wrong Answer", "Output Format Error" };
gets( a ); t = atoi( a ); //就只差在這行而已
for( int n = 1; n <= t; ++n )
{
gets( a );
gets( b );
printf( "Case %d: %s\n", n, result[ judge( a, b ) ] );
}
}