
Best regards
DM
Moderator: Board moderators
Thank a lot. I lost my source some time. I have it right now, did some modifications and got AC.stcheung wrote:Make sure you know it's a multiple input problem [...]
Hope this would end the WA mystery of this simple problem.
Code: Select all
#include <stdio.h>
char input[10][10] , click[10][10] , output[10][10] ;
int NumOfCase , grid ;
char process ( void ) ;
int main ( void )
{
int i ;
/* freopen ( "10279.in" , "r" , stdin ) ;
freopen ( "10279.out" , "w" , stdout ) ;*/
scanf ( "%i" , &NumOfCase ) ;
while ( NumOfCase -- )
{
scanf ( "%i" , &grid ) ;
for ( i = 0 ; i < grid ; i ++ )
scanf ( "%s" , input[i] ) ;
for ( i = 0 ; i < grid ; i ++ )
scanf ( "%s" , click[i] ) ;
if ( process ( ) )
{
for ( i = 0 ; i < grid ; i ++ )
printf ( "%s\n" , output[i] ) ;
}
else
{
for ( i = 0 ; i < grid ; i ++ )
printf ( "%s\n" , input[i] ) ;
}
printf ( "\n" ) ;
}
return 0 ;
}
char process ( void )
{
int i , j , counter ;
for ( i = 0 ; i < grid ; i ++ )
{
for ( j = 0 ; j < grid ; j ++ )
output[i][j] = '.' ;
output[i][j] = 0 ;
}
for ( i = 0 ; i < grid ; i ++ )
for ( j = 0 ; j < grid ; j ++ )
{
if ( click[i][j] == 'x' )
{
if ( input[i][j] == '*' )
return 0 ;
counter = 0 ;
if ( input[i-1][j-1] == '*' && i > 0 && j > 0 )
counter ++ ;
if ( input[i-1][j] == '*' && i > 0 )
counter ++ ;
if ( input[i-1][j+1] == '*' && i > 0 && j < grid - 1 )
counter ++ ;
if ( input[i][j-1] == '*' && j > 0 )
counter ++ ;
if ( input[i][j+1] == '*' && j < grid - 1 )
counter ++ ;
if ( input[i+1][j-1] == '*' && i < grid - 1 && j > 0 )
counter ++ ;
if ( input[i+1][j] == '*' && i < grid - 1 )
counter ++ ;
if ( input[i+1][j+1] == '*' && i < grid - 1 && j < grid - 1 )
counter ++ ;
output[i][j] = counter + '0' ;
}
}
return 1 ;
}
nop. the problem statement says:Is that mean if a mine has been touched, we only have to output the map contains asteriks and periods ... ????
here All other positions means all untouched positions that have no mines.Your output should represent the board, with each position filled in appropriately. Positions that have been touched and do not contain a mine should contain an integer between 0 and 8. If a mine has been touched, all positions with a mine should contain an asterisk. All other positions should contain a period.
Code: Select all
8
...**..*
......*.
....*...
........
........
.....*..
...**.*.
.....*..
xxxxxxxx
xxxx....
xxxx....
xxxxx...
xxxxx...
xxxxx...
xxx.....
xxxxx...
Code: Select all
001**22*
0013..*.
0001*...
00011...
00001...
00123*..
001**.*.
00123*..
Code: Select all
#include <stdio.h>
char input[10][10] , click[10][10] , output[10][10] ;
int NumOfCase , grid ;
void process ( void ) ;
int main ( void )
{
int i ;
/* freopen ( "10279.in" , "r" , stdin ) ;
freopen ( "10279.out" , "w" , stdout ) ;*/
scanf ( "%i" , &NumOfCase ) ;
while ( NumOfCase -- )
{
scanf ( "%i" , &grid ) ;
for ( i = 0 ; i < grid ; i ++ )
scanf ( "%s" , input[i] ) ;
for ( i = 0 ; i < grid ; i ++ )
scanf ( "%s" , click[i] ) ;
process ( ) ;
for ( i = 0 ; i < grid ; i ++ )
printf ( "%s\n" , output[i] ) ;
if ( NumOfCase ) printf ( "\n" ) ;
}
return 0 ;
}
void process ( void )
{
int i , j , k , l , counter ;
char kaboom = 0 ;
for ( i = 0 ; i < grid ; i ++ )
{
for ( j = 0 ; j < grid ; j ++ )
output[i][j] = '.' ;
output[i][j] = 0 ;
}
for ( i = 0 ; i < grid ; i ++ )
for ( j = 0 ; j < grid ; j ++ )
{
if ( click[i][j] == 'x' )
{
if ( input[i][j] == '*' )
{
if ( kaboom == 0 )
{
kaboom = 1 ;
for ( k = 0 ; k < grid ; k ++ )
for ( l = 0 ; l < grid ; l ++ )
{
if ( input[k][l] == '*' )
output[k][l] = '*' ;
}
}
}
else
{
counter = 0 ;
if ( input[i-1][j-1] == '*' && i > 0 && j > 0 )
counter ++ ;
if ( input[i-1][j] == '*' && i > 0 )
counter ++ ;
if ( input[i-1][j+1] == '*' && i > 0 && j < grid - 1 )
counter ++ ;
if ( input[i][j-1] == '*' && j > 0 )
counter ++ ;
if ( input[i][j+1] == '*' && j < grid - 1 )
counter ++ ;
if ( input[i+1][j-1] == '*' && i < grid - 1 && j > 0 )
counter ++ ;
if ( input[i+1][j] == '*' && i < grid - 1 )
counter ++ ;
if ( input[i+1][j+1] == '*' && i < grid - 1 && j < grid - 1 )
counter ++ ;
output[i][j] = counter + '0' ;
}
}
}
}
Code: Select all
char input[10][10] , click[10][10] , output[10][10] ;
Code: Select all
char input[10][11] , click[10][11] , output[10][11] ;
Does this mean an additional empty line or does it mean to printPrint a blank line between each consecutive 2 consecutive data sets.
Code: Select all
Removed after got AC