Page 5 of 7

Posted: Thu Aug 02, 2007 4:33 am
by rio
Try this case:

Code: Select all

2

2
.*
..
x.
xx

1
.
x
----
Rio

Re: A question of format, problem 10279 Minesweeper

Posted: Fri Apr 18, 2008 4:10 am
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

Re: 10279 - Mine Sweeper

Posted: Fri Apr 18, 2008 4:37 am
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.

Re: 10279 - Mine Sweeper

Posted: Sun Apr 20, 2008 1:52 am
by Mohamed Abd El-Monem
commented it but still WA :s

Re: 10279 - Mine Sweeper

Posted: Sun Apr 20, 2008 12:40 pm
by Jan
Read the description again, and try to understand when the stars (*) will be printed. Hope it helps.

WHY WA??

Posted: Sat Nov 15, 2008 5:18 pm
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;
}

Re: 10279 - Mine Sweeper

Posted: Fri Jul 17, 2009 7:48 am
by Jehad Uddin
getting WA pls help me

Code: Select all

got acc code deleted....

Re: 10279 - Mine Sweeper

Posted: Fri Jul 17, 2009 9:32 am
by sohel
You have to print a blank line between two consecutive outputs.

Re: 10279 - Mine Sweeper

Posted: Sun Jul 26, 2009 7:49 am
by Jehad Uddin
Thanks,i got acc..

Re: 10279 - Mine Sweeper

Posted: Mon Apr 30, 2012 10:24 am
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.. :)

Re: 10279 - Mine Sweeper

Posted: Mon Apr 30, 2012 8:37 pm
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

Re: 10279 - Mine Sweeper

Posted: Fri May 04, 2012 1:04 pm
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;}

Re: 10279 - Mine Sweeper

Posted: Fri May 04, 2012 9:13 pm
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.

Re: 10279 - Mine Sweeper

Posted: Fri May 04, 2012 11:45 pm
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;}


Re: 10279 - Mine Sweeper

Posted: Mon May 07, 2012 11:53 pm
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.