10279 - Mine Sweeper

All about problems in Volume 102. If there is a thread about your problem, please use it. If not, create one with its number in the subject.

Moderator: Board moderators

rio
A great helper
Posts: 385
Joined: Thu Sep 21, 2006 5:01 pm
Location: Kyoto, Japan

Post by rio »

Try this case:

Code: Select all

2

2
.*
..
x.
xx

1
.
x
----
Rio
Mohamed Abd El-Monem
New poster
Posts: 15
Joined: Mon Mar 31, 2008 1:20 am
Location: Egypt
Contact:

Re: A question of format, problem 10279 Minesweeper

Post by Mohamed Abd El-Monem »

hey all
i tried this test cases but i still get WA
this is my code and any one help me please

Code: Select all

# include <iostream>

using namespace std;





int main()
{
	int numOfgames;
	cin>>numOfgames;
	cout<<endl;
	bool blank = false;
	for (int N=0;N<numOfgames;N++)
	{
		if (blank)
			cout<<endl;
		int numOfR;
		cin>>numOfR;
		int Minesweeper[11][11];
		char board[11][11];
		char X[11][11];

		for(int i=0;i<numOfR;i++)
			for (int j=0;j<numOfR;j++)
				Minesweeper[i][j]=0;

		for (int i=0;i<numOfR;i++)
			for (int j=0;j<numOfR;j++)
				cin>>board[i][j];


		for (int i=0;i<numOfR;i++)
			for (int j=0;j<numOfR;j++)
				cin>>X[i][j];



		for(int i=0;i<numOfR;i++)
		{
			for (int j=0;j<numOfR;j++)
			{
				if (board[i][j] == '*')
				{
						if ( i == 0 && j == 0 )
						{
							Minesweeper[i][j+1]++;
							Minesweeper[i+1][j]++;
							Minesweeper[i+1][j+1]++;
						}


						else if ( i == 0 && j != 0 && j != numOfR-1 )
						{
							Minesweeper[i][j-1]++;
							Minesweeper[i][j+1]++;
							Minesweeper[i+1][j-1]++;
							Minesweeper[i+1][j]++;
							Minesweeper[i+1][j+1]++;
						}



						else if ( i == 0 && j == numOfR-1 )
						{
							Minesweeper[i][j-1]++;
							Minesweeper[i+1][j]++;
							Minesweeper[i+1][j-1]++;							
						}




						else if (i == numOfR-1 && j == 0)
						{
							Minesweeper[i][j+1]++;
							Minesweeper[i-1][j]++;
							Minesweeper[i-1][j+1]++;
						}



						else if ( j == 0 && i != 0 && i != numOfR-1 )
						{
							Minesweeper[i-1][j]++;
							Minesweeper[i-1][j+1]++;
							Minesweeper[i][j+1]++;
							Minesweeper[i+1][j]++;
							Minesweeper[i+1][j+1]++;

						}



						else if (i == numOfR-1 && j == numOfR-1)
						{
							Minesweeper[i][j-1]++;
							Minesweeper[i-1][j]++;
							Minesweeper[i-1][j-1]++;
						}



						else if (i == numOfR-1 && j != 0 && j != numOfR-1)
						{
							Minesweeper[i][j+1]++;
							Minesweeper[i][j-1]++;
							Minesweeper[i-1][j]++;
							Minesweeper[i-1][j-1]++;
							Minesweeper[i-1][j+1]++;

						}



						else if (j == numOfR-1 && i != 0 && i != numOfR-1)
						{
							Minesweeper[i-1][j]++;
							Minesweeper[i+1][j]++;
							Minesweeper[i-1][j-1]++;
							Minesweeper[i+1][j-1]++;
							Minesweeper[i][j-1]++;

						}



						else
						{
							Minesweeper[i][j-1]++;
							Minesweeper[i][j+1]++;
							Minesweeper[i-1][j]++;
							Minesweeper[i+1][j]++;
							Minesweeper[i-1][j-1]++;
							Minesweeper[i-1][j+1]++;
							Minesweeper[i+1][j-1]++;
							Minesweeper[i+1][j+1]++;
						}


					}

				}
			}



		for (int i=0;i<numOfR;i++)
		{
			for (int j=0;j<numOfR;j++)
			{
				if (X[i][j] == 'x')
				{
					if (board[i][j] == '*')
						cout<<'*';
					else
						cout<<Minesweeper[i][j];
				}
				else if (board[i][j] == '*')
					cout<<'*';
				else
					cout<<'.';

			}
			cout<<endl;

		}
		blank = true;
	}
	return 0;

}
thanx in advance
Jan
Guru
Posts: 1334
Joined: Wed Jun 22, 2005 10:58 pm
Location: Dhaka, Bangladesh
Contact:

Re: 10279 - Mine Sweeper

Post by Jan »

Code: Select all

   cin>>numOfgames;
   //cout<<endl; // This line should be commented
   bool blank = false;
   for (int N=0;N<numOfgames;N++)
Hope it helps.

P.S Don't forget to remove your codes after getting accepted.
Ami ekhono shopno dekhi...
HomePage
Mohamed Abd El-Monem
New poster
Posts: 15
Joined: Mon Mar 31, 2008 1:20 am
Location: Egypt
Contact:

Re: 10279 - Mine Sweeper

Post by Mohamed Abd El-Monem »

commented it but still WA :s
Jan
Guru
Posts: 1334
Joined: Wed Jun 22, 2005 10:58 pm
Location: Dhaka, Bangladesh
Contact:

Re: 10279 - Mine Sweeper

Post by Jan »

Read the description again, and try to understand when the stars (*) will be printed. Hope it helps.
Ami ekhono shopno dekhi...
HomePage
Enzam
New poster
Posts: 2
Joined: Wed Nov 05, 2008 5:39 pm

WHY WA??

Post by Enzam »

Checked All the test cases. Please help me to find the bug.


#include <stdio.h>

int main()
{
int t;
char isNotFirst=0;
for(scanf("%d",&t);t;t--)
{
char grid[14][14]={0};
int dim;
int i, j;
char game[14][14]={0};
if(isNotFirst) printf("\n");
isNotFirst++;
scanf("%d",&dim);
for(i=1;i<=dim;i++)
{
char *x=&grid[1];
scanf("%s",x);
}
int reveal=0;
for(i=1;i<=dim;i++)
{
char *x=&game[1];
scanf("%s",x);
for(j=1;j<=dim;j++)
{
if(reveal==1 && grid[j]=='*') game[j]='*';
if(game[j]=='x')
{
if(grid[j]=='*')
{
game[j]='*';
reveal=1;
}
else
{
int count=0;
if(grid[i-1][j-1]=='*') count++;
if(grid[i-1][j]=='*') count++;
if(grid[i-1][j+1]=='*') count++;
if(grid[j-1]=='*') count++;
if(grid[j]=='*') count++;
if(grid[j+1]=='*') count++;
if(grid[i+1][j-1]=='*') count++;
if(grid[i+1][j]=='*') count++;
if(grid[i+1][j+1]=='*') count++;
game[i][j]=count+'0';
}
}
}
}

for(i=1;i<=dim;i++)
{
char *x=&game[i][1];
printf("%s\n",x);
}

}
return 0;
}
Jehad Uddin
Learning poster
Posts: 74
Joined: Fri May 08, 2009 5:16 pm

Re: 10279 - Mine Sweeper

Post by Jehad Uddin »

getting WA pls help me

Code: Select all

got acc code deleted....
Last edited by Jehad Uddin on Sun Jul 26, 2009 7:50 am, edited 1 time in total.
sohel
Guru
Posts: 856
Joined: Thu Jan 30, 2003 5:50 am
Location: New York

Re: 10279 - Mine Sweeper

Post by sohel »

You have to print a blank line between two consecutive outputs.
Jehad Uddin
Learning poster
Posts: 74
Joined: Fri May 08, 2009 5:16 pm

Re: 10279 - Mine Sweeper

Post by Jehad Uddin »

Thanks,i got acc..
elmagnifico
New poster
Posts: 5
Joined: Mon Apr 30, 2012 10:15 am

Re: 10279 - Mine Sweeper

Post by elmagnifico »

I tried almost all test case i could think of but i am getting wrong answer. Please help
Here is my code..


Got acc..Thanks.. No blank line should be printed after the last test case.. :)
Last edited by elmagnifico on Mon Apr 30, 2012 10:00 pm, edited 1 time in total.
jariasf
New poster
Posts: 2
Joined: Fri Jul 01, 2011 3:39 pm

Re: 10279 - Mine Sweeper

Post by jariasf »

@elmagnifico: As sohel said: "You have to print a blank line between two consecutive outputs."

That's to say if I had 2 cases:

2

Case 1
<space>
Case 2
<No Space>

In your code you're doing the following:
2

Case 1
<space>
Case 2
<space> <---
This is wrong.

So you can put the next line after the first loop:

Code: Select all

for(i=1;i<=t;i++)
{
     if( i > 1 ) System.out.println();
and erase the last System.out.println():

Code: Select all

for(j=0;j<n;j++)
{
     for(k=0;k<n;k++)
     {
	if(a[j][k]=='*' && flag==1)
	   System.out.print(a[j][k]);
	else if(b[j][k]=='x')
	   System.out.print(c[j][k]);
	else System.out.print(".");
     }
     System.out.println();
}
//System.out.println();  <-- This you have to erase or just comment
Nafis0001
New poster
Posts: 6
Joined: Fri Mar 23, 2012 10:02 pm

Re: 10279 - Mine Sweeper

Post by Nafis0001 »

what's wrong in my code????please someone help and give me some clue......Here is my code below....

Code: Select all

#include<stdio.h>
#include<string.h>
int main()
{int t,i,j,n,b[15][15],c[15][15],k;char a[15];
 scanf("%d",&t);
 printf("\n");
 for(k=1;k<=t;k++)
 {for(i=0;i<15;i++)
  for(j=0;j<15;j++)
  b[i][j]=0;
  scanf("%d\n",&n);
  for(i=1;i<=n;i++)
  {gets(a);
   for(j=0;j<n;j++)
   {if(a[j]=='*')
    {b[i][j+1]=32;
     b[i][j+2]++;
     b[i][j]++;
     b[i-1][j+1]++;
     b[i+1][j+1]++;
     b[i-1][j]++;
     b[i-1][j+2]++;
     b[i+1][j+2]++;
     b[i+1][j]++;
        }}}
  for(i=0;i<15;i++)
  for(j=0;j<15;j++)
  c[i][j]=0;
    int d=0;
   for(i=1;i<=n;i++)
   {gets(a);
    for(j=0;j<n;j++)
    {if(a[j]=='x')
     {if(b[i][j+1]>=32)
      d++;
     c[i][j+1]=1;}}}

    for(i=1;i<=n;i++)
    {for(j=1;j<=n;j++)
     {if(d>0)
      {if(b[i][j]>=32)
        {printf("*");
        continue;}}
      else if(c[i][j]>0)
      printf("%d",b[i][j]);
      else
      printf(".");}
      printf("\n");}
     if(k!=t)
     printf("\n");}
    return 0;}
brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 10279 - Mine Sweeper

Post by brianfry713 »

Print a blank line between each data set.

Your code prints a blank line at the start of the output, don't do that.
Check input and AC output for thousands of problems on uDebug!
Nafis0001
New poster
Posts: 6
Joined: Fri Mar 23, 2012 10:02 pm

Re: 10279 - Mine Sweeper

Post by Nafis0001 »

I changed my code as below but still wrong ans....

Code: Select all

    #include<stdio.h>
    #include<string.h>
    int main()
    {int t,i,j,n,b[15][15],c[15][15],k;char a[15];
     scanf("%d",&t);
     printf("\n");
     for(k=1;k<=t;k++)
     {for(i=0;i<15;i++)
      for(j=0;j<15;j++)
      b[i][j]=0;
      scanf("%d\n",&n);
      for(i=1;i<=n;i++)
      {gets(a);
       for(j=0;j<n;j++)
       {if(a[j]=='*')
        {b[i][j+1]=32;
         b[i][j+2]++;
         b[i][j]++;
         b[i-1][j+1]++;
         b[i+1][j+1]++;
         b[i-1][j]++;
         b[i-1][j+2]++;
         b[i+1][j+2]++;
         b[i+1][j]++;
            }}}
      for(i=0;i<15;i++)
      for(j=0;j<15;j++)
      c[i][j]=0;
        int d=0;
       for(i=1;i<=n;i++)
       {gets(a);
        for(j=0;j<n;j++)
        {if(a[j]=='x')
         {if(b[i][j+1]>=32)
          d++;
         c[i][j+1]=1;}}}
          if(k!=t)
         printf("\n");
        for(i=1;i<=n;i++)
        {for(j=1;j<=n;j++)
         {if(d>0)
          {if(b[i][j]>=32)
            {printf("*");
            continue;}}
          else if(c[i][j]>0)
          printf("%d",b[i][j]);
          else
          printf(".");}
          printf("\n");}
        }
        return 0;}

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 10279 - Mine Sweeper

Post by brianfry713 »

Print a blank line between each data set.

Your code prints two blank lines at the start of the output, don't do that.
Check input and AC output for thousands of problems on uDebug!
Post Reply

Return to “Volume 102 (10200-10299)”