10189 - Minesweeper

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

Moderator: Board moderators

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

Re: 10189 Minesweeper WA....

Post by brianfry713 »

Check input and AC output for thousands of problems on uDebug!
biplabks
New poster
Posts: 7
Joined: Sun Mar 09, 2014 11:20 am

Re: 10189 Minesweeper - WA

Post by biplabks »

Hi..I have the same output as yours...it may be something with blank line...i m not sure though...can u please help?

Field #1:
3*33*32*34**4*5**33***5*4****3***3*22*34***34**4***5****3*4***2****4**11*22**3***5*3***32****102*432
***5**44****4***4**56****43445***522*4***54*****57****54*4***42234**432124*435*7***546**336*5212****
*7**5**5***424*546**4*66*311**55**333*456*556*55****43*22*35*42222333*222**43**5*8**5***54**5*3224*4
**434*7****323*4***7*5**5*335*5*55**334******22****412343335*5**5*44*4*2*44**446***********7***3334*
24*23*****6*2*4*56***5***4**4*6**4*6*3****7*43334**423***5****5******42334*444***7***7*555***53***4*
14*33*65***5435*6**7*42323*33**6*54**4466**34**335**2*******65*56**76*22**5*2**7*6****4*5*45*535*54*
*5*54**44****3****6**211234435*6**4*54***444***5**4332346*8**5*4******44***444**5**7*43***54***5*4*3
*6***6**24*8*5345*5*323*4****4**435*5***43**666**54*2223******34*7*7*6**66**3*5**44**324****5**7*42*
**6***5323***4*22*5433***5**6*5*21**6**32*6*****5**5*5**446**43*4**7*7****434*324*5433*44**6*5***222
***35**33*7*44*534***5*745*7**534455**5433***8**433*****42**44*44*******534*54324***33*4*4**46*6433*
3*312**6****43***5*65****4****5*****43***224***6*236*****3234***54557**55*6****3**8*4*5*4445****4**3
234234***6***34**7**6**634*5***4**7*324*531124**32***7*6*311**6***4***5*******55****54**4**3*6*4***3
2***2*333*4*4*23*******3*2123*323*4*21*3**10013*213**4*32*1123*4***4*33**5****3***43**4*32222*22233*
abarbosa94
New poster
Posts: 2
Joined: Tue May 13, 2014 11:56 pm

Re: 10189 Minesweeper WA....

Post by abarbosa94 »

Can anyone help me to fix it up? I don't know why I got wrong answer

Code: Select all

import java.io.*;
import java.util.*;

class Main
{
 static String ReadLn (int maxLg)  // utility function to read from stdin
 {
     byte lin[] = new byte [maxLg];
     int lg = 0, car = -1;
     String line = "";

     try
     {
         while (lg < maxLg)
         {
             car = System.in.read();
             if ((car < 0) || (car == '\n')) break;
             lin [lg++] += car;
         }
     }
     catch (IOException e)
     {
         return (null);
     }

     if ((car < 0) && (lg == 0)) return (null);  // eof
     return (new String (lin, 0, lg));
 }

 public static void main (String args[])  // entry point from OS
 {
     Main myWork = new Main();  // create a dinamic instance
     myWork.Begin();            // the true entry point
 }

 void Begin()
 {
     String input; //entra com uma entrada
     StringTokenizer idata; //quebra essa entrada em pedaçoes
     int a, b;
     int count = 0;

     while ((input = Main.ReadLn (255)) != null) //A string input recebe a linha inteira

     {
       if(input.equals("0 0")) break;  //eh string, logo, usa equals
       idata = new StringTokenizer (input);
       a = Integer.parseInt (idata.nextToken());
       b = Integer.parseInt (idata.nextToken());
       char[][] array = new char[a][b];
       for(int i = 0;i<array.length;i++){
    	   input = Main.ReadLn(255); //le a string a ser inserida pra formar o campo 
    	   for(int j = 0; j<array[i].length; j++){
    		   array[i][j] = input.charAt(j);
    	   }
       }
       count++;
       printGame(ProduceGame(array, a, b),count);
       System.out.println();
     }
 }

 char[][] ProduceGame(char[][] array, int a, int b){
	 char[][] matrix = new char[a][b];
	 matrix = inicialize(a,b);
	 String x = "*";
	 int temp = 0;
	 for(int i = 0; i< a; i++){
		 for(int j = 0; j< b; j ++){
			if(array[i][j] == x.charAt(0)){
				matrix[i][j] = array[i][j];
				//48 eh zero na tabela ASCII, entao so adicionar 48 a tudo
				if(i!=0 && j!=0) {
					temp = Character.getNumericValue(matrix[i-1][j-1]);
					temp++;
					if(array[i-1][j-1] != x.charAt(0)) matrix[i-1][j-1] = (char)(temp+48); //verifica se a posicao n contem bomba
					
				}
				if(i!=0){
					temp = Character.getNumericValue(matrix[i-1][j]);
					temp++;
					if(array[i-1][j] != x.charAt(0)) matrix[i-1][j] = (char)(temp+48);
				} 
				if(j!=0){
					temp = Character.getNumericValue(matrix[i][j-1]);
					temp++;
					if(array[i][j-1] != x.charAt(0)) matrix[i][j-1]= (char)(temp+48);
				} 			
				if(i != a-1 && j !=0){
					temp = Character.getNumericValue(matrix[i+1][j-1]);
					temp++;
					if(array[i+1][j-1] != x.charAt(0)) matrix[i+1][j-1] = (char)(temp+48);
				} 
				if(i != 0 && j != b-1){
					temp = Character.getNumericValue(matrix[i-1][j+1]);
					temp++;
					if(array[i-1][j+1] != x.charAt(0)) matrix[i-1][j+1] = (char)(temp+48);
				} 
				if(i!=a-1 && j!= b-1){
					temp = Character.getNumericValue(matrix[i+1][j+1]);
					temp++;
					if(array[i+1][j+1] != x.charAt(0)) matrix[i+1][j+1] = (char)(temp+48);
				} 
				if(i!=a-1){
					temp = Character.getNumericValue(matrix[i+1][j]);
					temp++;
					if(array[i+1][j] != x.charAt(0)) matrix[i+1][j] = (char)(temp+48); 
				} 
				if(j!=b-1){
					temp = Character.getNumericValue(matrix[i][j+1]);
					temp++;
					if(array[i][j+1] != x.charAt(0)) matrix[i][j+1] = (char)(temp+48);	
				} 
			}
			temp = 0;
		 }
	 }
	 return matrix;
 }
 
 char[][] inicialize(int a, int b){
	 char[][] produced = new char[a][b];
	 for(int i = 0; i< a; i++){	 
		 for(int j = 0; j< b; j++){
			produced[i][j] = '0';	
		 }
	 }
	 return produced;
 }
 void printGame(char[][] a, int count){
	 System.out.println("Field #"+count+":");
	 for(int i = 0; i<a.length; i++){
		 for(int j = 0; j< a[i].length; j++){
			 System.out.print(a[i][j]);
		 }
		 System.out.println();
	 }
 }


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

Re: 10189 Minesweeper WA....

Post by brianfry713 »

brianfry713 wrote:There must be an empty line between field outputs. Don't print an extra blank line at the end.
Check input and AC output for thousands of problems on uDebug!
abarbosa94
New poster
Posts: 2
Joined: Tue May 13, 2014 11:56 pm

Re: 10189 Minesweeper WA....

Post by abarbosa94 »

But it will produce an Presentation Error, right? I got Wrong Answer...
brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 10189 Minesweeper WA....

Post by brianfry713 »

No, extra or missing newline char's will give you WA. Don't ever count on getting PE.
Check input and AC output for thousands of problems on uDebug!
sepalacio
New poster
Posts: 1
Joined: Mon May 26, 2014 6:50 am

PLZ Help with 10189 Minesweeper WA.

Post by sepalacio »

i have several hours trying to discover what is wrong with my code, but i can't. :( :( :(
i compute many samples with my code and compare it with uva toolkit and is the same output.

I WILL APRECIATE ANY HELP SOMEONE COULD GIVE ME... :D
here is my code in JAVA:
_________________________________________________________________________________-
import java.io.*;

public class Main{

public static void main (String []ar) throws IOException {

BufferedReader b=new BufferedReader(new InputStreamReader(System.in));


int n,m,con=0;
int [][] matrizentera;
String [][] matriz;
String [][] matrizre;
n=1;
m=1;

while (n!=0 && m!=0)
{
String linea1;
linea1=b.readLine();
String [] V1 =new String[linea1.length()];
V1=linea1.split(" ");

n=Integer.parseInt(V1[0]);
m=Integer.parseInt(V1[1]);


if (n!=0 && m!=0)
{
con++;
if (con>1)
{
System.out.println("");
}

matriz=new String [n+2][m+2];
matrizre=new String [n+2][m+2];
matrizentera=new int [n+2][m+2];

for(int s=0;s<n+2;s++)
{
for (int j=0;j<m+2;j++)
{
matriz[s][j]=".";
}
}

for(int s=0;s<n+2;s++)
{
for (int j=0;j<m+2;j++)
{
matrizentera[s][j]=0;
}
}


for(int x=1;x<n+2;x++)
{
String linea;
linea=b.readLine();
String [] V =new String[linea.length()];
V=linea.split("");

for (int y=1;y<m+2;y++)
{
matriz[x][y]=V[y-1];
if (y==m)
{
break;
}
} if (x==n)
{
break;
}
}



for (int x=1;x<n+1;x++)
{

for (int y=1;y<m+1;y++)
{

if(matriz[x][y].equals("*"))
{

matrizentera[x][y]=-1;

if ( !matriz[x][y+1].equals("*"))
{
matrizentera[x][y+1]++;
}
if ( !matriz[x][y-1].equals("*"))
{
matrizentera[x][y-1]++;
}
if ( !matriz[x-1][y].equals("*"))
{
matrizentera[x-1][y]++;
}
if ( !matriz[x+1][y].equals("*"))
{
matrizentera[x+1][y]++;
}
if ( !matriz[x-1][y+1].equals("*"))
{
matrizentera[x-1][y+1]++;
}
if ( !matriz[x-1][y-1].equals("*"))
{
matrizentera[x-1][y-1]++;
}
if ( !matriz[x+1][y+1].equals("*"))
{
matrizentera[x+1][y+1]++;
}
if ( !matriz[x+1][y-1].equals("*"))
{
matrizentera[x+1][y-1]++;
}


}
}
}


for(int s=0;s<n+2;s++)
{
for (int j=0;j<m+2;j++)
{
if (matrizentera[s][j]==-1)
{
matrizre[s][j]="*";
}else
{
matrizre[s][j]= Integer.toString(matrizentera[s][j]);
}

}

}


System.out.println("Field #"+con+":");

for(int s=1;s<n+1;s++)
{
for (int j=1;j<m+1;j++)
{
System.out.print(matrizre[s][j]);

} System.out.println("");

}

}


}

}

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

Re: 10189 Minesweeper WA....

Post by brianfry713 »

Doesn't match the sample I/O
http://ideone.com/fyfInf
Check input and AC output for thousands of problems on uDebug!
double_zero
New poster
Posts: 8
Joined: Sat Jun 28, 2014 12:42 pm

Re: 10189 - Minesweeper

Post by double_zero »

Somebody Please Help Me, I Don't Know Why I Get Wrong Answer,

Code: Select all

#include <iostream>
#include <algorithm>

using namespace std;
int  n=1,m=1; 
char a[101][101], b[101][101];

char calc(int p, int q){
	int c=0;
	if(a[p][q]=='*') return '*';
	for(int i=p-1 ; i<=p+1 ; i++){
		for(int j=q-1 ; j<=q+1 ; j++){
			if( !((i==p && j==q) && (i<0 && i>=n) && (j<0 && j>=m)) )
				if(a[i][j]=='*') c++;
		}
	}
	return c+'0';
}

int main(){
	
	int tc=0;
	while(true){
		cin >> n >> m;
		if(n==0 && m==0) break;
		
		for(int i=0 ; i<n; i++){
			for(int j=0 ; j<m; j++){
				cin >> a[i][j];
			}
		}
		for(int i=0 ; i<n; i++){
			for(int j=0 ; j<m; j++){
				b[i][j]=calc(i,j);
			}
		}

		cout << "Field #" << ++tc << ":" << endl;
		for(int i=0 ; i<n; i++){
			for(int j=0 ; j<m; j++){
				cout << b[i][j];
			}
			cout << endl;
		}
		cout << endl;
	}
}
lbv
Experienced poster
Posts: 128
Joined: Tue Nov 29, 2011 8:40 am

Re: 10189 - Minesweeper

Post by lbv »

double_zero wrote:Somebody Please Help Me, I Don't Know Why I Get Wrong Answer
I suggest you always start by taking the time to read the previous messages in the forums. Check for example the message posted by brianfry713 around Nov 14, 2013, which is relevant to your program.
axelblaze
New poster
Posts: 34
Joined: Mon Jun 23, 2014 7:45 pm

Re: 10189 - Minesweeper

Post by axelblaze »

Please help me I am getting RE...

Code: Select all

#include<iostream>
#include<cstdio>
using namespace std;

int main()
{
    //freopen("input.txt","r",stdin);
    int m,n,field=0;
    while(cin>>m>>n,m || n)
    {
        char a[m][n];
        for(int i=0;i<m;i++)
            for(int j=0;j<n;j++)
                a[i][j]='0';
        cin.ignore();
        for(int i=0;i<m;i++)
        {
            for(int j=0;j<n;j++)
            {
                char ch=getchar();
                if(ch=='*')
                {
                    a[i-1][j-1]+=(i>0&&j>0&&a[i-1][j-1]!='*');
                    a[i-1][j]+=(i>0&&a[i-1][j]!='*');
                    a[i-1][j+1]+=(i>0&&j<n&&a[i-1][j+1]!='*');
                    a[i][j-1]+=(j>0&&a[i][j-1]!='*');
                    a[i][j]='*';
                    a[i][j+1]+=(j<n&&a[i][j+1]!='*');
                    a[i+1][j-1]+=(i<m&&j>0&&a[i+1][j-1]!='*');
                    a[i+1][j]+=(i<m&&a[i+1][j]!='*');
                    a[i+1][j+1]+=(i<m&&j<n&&a[i+1][j+1]!='*');
                }
            }
            cin.ignore();
        }
        if(field)cout<<endl;
        cout<<"Field #"<<++field<<endl;
        for(int i=0;i<m;i++)
            {
            for(int j=0;j<n;j++)
            cout<<a[i][j];
            cout<<endl;
            }
    }
    return 0;
}
Is it because I'm increasing values that are out of array bounds..?
But according to my code, the values will never increase if the pointer is out of array bounds...
Thanks in advance... :) :) :)
axelblaze
New poster
Posts: 34
Joined: Mon Jun 23, 2014 7:45 pm

Re: 10189 - Minesweeper

Post by axelblaze »

now I wrote the char a[105][105] outside the loop..
but this time I got WA...
please help...

Code: Select all

removed after ac
Last edited by axelblaze on Thu Aug 07, 2014 3:59 pm, edited 3 times in total.
brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 10189 - Minesweeper

Post by brianfry713 »

You're missing the : after Field
Check input and AC output for thousands of problems on uDebug!
axelblaze
New poster
Posts: 34
Joined: Mon Jun 23, 2014 7:45 pm

Re: 10189 - Minesweeper

Post by axelblaze »

thanks biyanfry!! it was a stupid mistake though...!
Shahidul.CSE
Experienced poster
Posts: 148
Joined: Sun Jul 13, 2014 4:32 am
Location: Rangpur, Bangladesh

Re: 10189 - Minesweeper

Post by Shahidul.CSE »

Code: Select all

Removed after accepted ! :D 
Last edited by Shahidul.CSE on Fri Aug 15, 2014 5:09 am, edited 1 time in total.
Md. Shahidul Islam
Dept. of CSE at Begum Rokeya University, Rangpur, Bangladesh
UVa id: http://uhunt.felix-halim.net/id/438420
My facebook account,
Email me: shahidul.cse.brur@gmail.com
Post Reply

Return to “Volume 101 (10100-10199)”