10189 - Minesweeper

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

Moderator: Board moderators

10189

Postby code_man » Wed Feb 14, 2007 7:51 pm

what is wrong with this code? I have WA.. I don't undersand why...?

Code: Select all
#include<iostream>
using namespace std;

char check(char t)
{
 int i=0;
 if(t!=42) i=1;
  return i;   
}

main()
{
int a, b, it=1;

 while(cin>>a>>b)
 {
  if((a==0) && (b==0)) break;
 
  char **t;
  t= new char*[a+5];
  for(int i=0; i<a+5; i++)
   t[i] = new char[b+5];
   
  for(int i=0; i<a+5; i++)
   {
     for(int j=0; j<b+5; j++)
      t[i][j]=48;
   }
   
  char z;
  for(int i=1; i<a+1; i++)
   {
     for(int j=1; j<b+1; j++)
      {
        cin>>z;
        if(z==42)
         {
          t[i][j]=42;         
          t[i-1][j-1]+=check(t[i-1][j-1]);
          t[i-1][j]+=check(t[i-1][j]);
          t[i-1][j+1]+=check(t[i-1][j+1]);
          t[i][j-1]+=check(t[i][j-1]);
          t[i][j+1]+=check(t[i][j+1]);
          t[i+1][j-1]+=check(t[i+1][j-1]);
          t[i+1][j]+=check(t[i+1][j]);
          t[i+1][j+1]+=check(t[i+1][j+1]);       
         }   
      }
    }
 
  cout<<"\nField #"<<it++<<"\n";
  for(int i=1; i<a+1; i++)
   {   
    for(int j=1; j<b+1; j++)
     {
      cout<<t[i][j];
     }
    cout<<"\n";
    }
 
   
  for(int i=a; i<a+5; i++)
    delete [] t[i];
   delete [] t;
 }     
}
Last edited by code_man on Fri Feb 23, 2007 10:16 pm, edited 1 time in total.
code_man
New poster
 
Posts: 4
Joined: Tue Jan 16, 2007 6:07 pm

Postby big_mac » Thu Feb 15, 2007 1:24 am

The first things I can see is that you are printing a '\n' before the first 'Field', and no ':' after the field number.
big_mac
New poster
 
Posts: 1
Joined: Thu Feb 15, 2007 1:22 am

10189:how to present

Postby m2lajoo » Thu Feb 15, 2007 6:09 pm

help me! why my program say presentation error :cry:
Code: Select all
var
m,n:byte;
test:integer;
house:array[1..100,1..100]of char;
st:string;
khane:array[1..100,1..100]of (mine,clear);
h:array[1..100,1..100]of byte;
i,j:integer;
function shownumber(num1,num2:integer):integer;
var
x,y,tedad:integer;
begin
tedad:=0;
for x:=num1-1 to num1+1 do
for y:=num2-1 to num2+1 do
if (khane[x,y]=mine)and(x<=m)and(x>=1)and(y<=n)and(y>=1) then
tedad:=tedad+1;
shownumber:=tedad;
end;
begin
readln(m,n);
test:=1;
while (m<>0)or(n<>0) do
begin
for i:=1 to m do
for j:=1 to n do
begin
khane[i,j]:=clear;
house[i,j]:='.';
h[i,j]:=0;
end;
for i:=1 to m do
begin
readln(st);
for j:=1 to length(st) do
house[i,j]:=st[j];
end;
writeln('Field #',test,':');
for i:=1 to m do
for j:=1 to n do
if house[i,j]='*' then
khane[i,j]:=mine
else
khane[i,j]:=clear;
for i:=1 to m do
for j:=1 to n do
if khane[i,j]<>mine then
h[i,j]:=shownumber(i,j);
for i:=1 to m do
begin
for j:=1 to n do
if khane[i,j]<>mine then
write(h[i,j])
else
write('*');
writeln;
end;
writeln
test:=test+1;
readln(m,n);
end;
end.
m2lajoo
New poster
 
Posts: 11
Joined: Thu Jan 11, 2007 9:21 am
Location: iran

Postby helloneo » Thu Feb 15, 2007 6:41 pm

Just try to search first.. and..
Do not make a new thread if there is one already..

http://online-judge.uva.es/board/viewtopic.php?t=8869

Don't forget to remove your code after AC.. :)
helloneo
Guru
 
Posts: 516
Joined: Mon Jul 04, 2005 6:30 am
Location: Seoul, Korea

Postby code_man » Fri Feb 23, 2007 9:58 pm

thx big_mac for you help..:) Now I know whats was incorrect..
code_man
New poster
 
Posts: 4
Joined: Tue Jan 16, 2007 6:07 pm

10189 WA

Postby KaDeG » Sun Mar 04, 2007 9:45 pm

I have made the minsweeper program but i got WA,
I checked some testcases I found in the forums and everything works fine,
any ideas where the probelm is?
Code: Select all
Code, deleted, thanks

I'm a bit complicate with all thes \n that can give a WA, any suggestion would be very hepful, thanks.
Last edited by KaDeG on Mon Mar 05, 2007 1:34 pm, edited 1 time in total.
/*No Comment*/
User avatar
KaDeG
New poster
 
Posts: 13
Joined: Sun Mar 04, 2007 8:40 pm

Postby arif_pasha » Mon Mar 05, 2007 11:26 am

1. use gets() to get the line.
2. use larger array size [say 110]

Hope it helps..
arif_pasha
New poster
 
Posts: 42
Joined: Fri Jun 13, 2003 3:47 pm
Location: Dhaka , Bangladesh

Postby KaDeG » Mon Mar 05, 2007 1:32 pm

ok, the problem was only the Max of the tables i make the tables at 110 and it was accepted, thanks, real thanks arif pasha, it's also works with Tables with 101!
/*No Comment*/
User avatar
KaDeG
New poster
 
Posts: 13
Joined: Sun Mar 04, 2007 8:40 pm

10189 - Output Limit Exceeded!!

Postby Amichelg75 » Wed Mar 07, 2007 9:42 pm

Hello, My code is:

/***********************
solution to problem ,
by: Adrian Michel
date: 06/03/2007
***********************/

#include<stdio.h>
#include<string.h>
main(){

char Minesweeper[100][100];
int NFilas, NColumnas, li, lj, ContBombs, ContFields;

ContFields = 1;

do{
/* Captura del Numero de Filas y Columnas */
scanf("%d %d", &NFilas, &NColumnas);
fflush(stdin);
/* Captura del tablero de Minesweeper */
if( (NFilas > 0) && (NColumnas > 0) )
{

for ( li = 0; li < NFilas; li ++ )
{

for ( lj = 0; lj < NColumnas; lj++ )
{
scanf("%c", &Minesweeper[li][lj]);
}
fflush(stdin);
} /*Fin Captura*/

/* Transformacion de la Matriz*/
for ( li = 0;li < NFilas; li++ )
{

for ( lj = 0; lj < NColumnas; lj++)
{

if ( Minesweeper[li][lj] =='.' )
{

ContBombs = 0;

if ( (li-1 >=0) && (lj-1 >= 0) &&
( Minesweeper[li-1][lj-1] == '*' ) )
{
ContBombs ++;
}
if ( (lj-1 >= 0) &&
( Minesweeper[li][lj-1] == '*' ) )
{
ContBombs ++;
}
if ( (li+1 < NFilas) && (lj-1 >= 0) &&
( Minesweeper[li+1][lj-1] == '*' ) )
{
ContBombs ++;
}
if ( (li-1 >=0) && (lj+1 < NColumnas) &&
( Minesweeper[li-1][lj+1] == '*' ) )
{
ContBombs ++;
}
if ( (lj+1 < NColumnas) &&
( Minesweeper[li][lj+1] == '*' ) )
{
ContBombs ++;
}
if ( (li+1 < NFilas) && (lj+1 < NColumnas) &&
( Minesweeper[li+1][lj+1] == '*' ) )
{
ContBombs ++;
}
if ( (li-1 >= 0) &&
( Minesweeper[li-1][lj] == '*' ) )
{
ContBombs ++;
}
if ( (li+1 < NFilas) &&
( Minesweeper[li+1][lj] == '*' ) )
{
ContBombs ++;
}
switch (ContBombs)
{
case 0:
Minesweeper[li][lj] = '0';
break;
case 1:
Minesweeper[li][lj] = '1';
break;
case 2:
Minesweeper[li][lj] = '2';
break;
case 3:
Minesweeper[li][lj] = '3';
break;
case 4:
Minesweeper[li][lj] = '4';
break;
case 5:
Minesweeper[li][lj] = '5';
break;
case 6:
Minesweeper[li][lj] = '6';
break;
case 7:
Minesweeper[li][lj] = '7';
break;
case 8:
Minesweeper[li][lj] = '8';
break;
} /*Fin Switch*/
} /*Fin Si '.'*/

} /*Fin For lj*/
}/*Fin For li*/

/*Mostrar Resultados*/
printf ("Field #%d:\n", ContFields);
for ( li = 0;li < NFilas; li++ )
{

for ( lj = 0; lj < NColumnas; lj++)
{
printf ("%c", Minesweeper[li][lj]);
}
printf("\n");
} /*Fin For Imprime*/

printf ("\n");
ContFields ++;
}
}while(NFilas > 0 && NColumnas > 0);
return 0;
}

online-Judged Output Limit Exceeded!!, Why? :-?
Amichelg75
New poster
 
Posts: 1
Joined: Wed Mar 07, 2007 9:35 pm

10189 WA?? PLZ HELP!!

Postby deadhunter411 » Tue Mar 20, 2007 10:38 am

about the ouput "\n"
"There must be an empty line between field outputs."
Am I right when input is "0 0" ??

thank you for help!!!:)

Code: Select all
#include<stdio.h>

int main()
{
   int k,l,size_1,size_2,i,j,I,J,boom=0,num=1,end=0;
   char a[200][200];
   char b[200][200];

   scanf(" %d %d",&size_1,&size_2);

   while(size_1!=0 && size_2!=0)
   {

      for(k=0;k<size_1;k++)   
         for(l=0;l<size_2;l++)
            scanf(" %c",&a[k][l]);   

      for(i=0;i<size_1;i++)
      {
         for(j=0;j<size_2;j++)
         {            
            if(a[i][j]=='*')
            {
               b[i][j]=a[i][j];
               continue;
            }
            else if(a[i][j]=='.')
            {
               for(I=i-1;I<i+2;I++)
               {
                  for(J=j-1;J<j+2;J++)
                  {
                     if(I<0 || J<0 || I==i && J==j)
                        continue;
                     else if(a[I][J]=='*')
                        boom++;
                  }
               }
               b[i][j]=boom;
               boom=0;
            }         
         }
      }

      if(end)
         printf("\n");

      printf("Field #%d:\n",num++);

      for(k=0;k<size_1;k++)
      {   
         for(l=0;l<size_2;l++)
         {      
            if(b[k][l]=='*')
               printf("%c",b[k][l]);
            else
               printf("%d",b[k][l]);
         }
         printf("\n");
         
      }

      end=1;

      scanf(" %d %d",&size_1,&size_2);

   }
   return 0;
}
deadhunter411
New poster
 
Posts: 8
Joined: Sat Mar 10, 2007 10:20 am

WA-Help

Postby Neli » Sun May 13, 2007 8:24 am

I took in the input in a Long array,and checked 8 particular case.
Couldn't understand,why wrong answer.
Plz help me.
Neli
New poster
 
Posts: 7
Joined: Thu May 03, 2007 8:35 am
Location: Sylhet

10189 in Java - WA

Postby dttri » Sun May 13, 2007 9:39 am

Hi everybody,
I search the forums but can't find any topic similar to mine. I'm sure about the "empty line between case" as many other topics. Is there any wrong with my code?

Thank you

Code: Select all

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

class Main
{
   //This is a utility function to read from stdin
   //provided by UVA: do not modify
   static String readLine (int maxLg)
   {
      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));
   }
   
   static void writeLine(String s)
   {
      System.out.println(s);
   }
   
   static void writeLine()
   {
      System.out.println();
   }
   
   
   //entry point from OS
   public static void main (String[] args)
   {
      Main myWork = new Main();  // create a dinamic instance
      myWork.begin();            // the true entry point
   }

   void begin()
   {
      String input;
      StringTokenizer idata;
      char[][] cell;
      char[][] output;
      int row,col;
      int caseNumber=1;
      while(true)
      {
         input = readLine(255);
         idata = new StringTokenizer(input);
         row = Integer.parseInt(idata.nextToken());
         col = Integer.parseInt(idata.nextToken());
         if(row==0 && col==0)break;
         cell = new char[row][col];
         output = new char[row][col];
         //read all row and assign output
         for(int i=0;i<row;i++)
         {
            input=readLine(255);
            //assign value for each cell
            for(int j=0;j<col;j++)
            {
               cell[i][j]=input.charAt(j);
               output[i][j]='0';
            }
         }
         //process all cell
         for(int i=0;i<row;i++)
         {
            for(int j=0;j<col;j++)
            {
               if(cell[i][j]=='*')
               {
                  output[i][j]='*';
                  continue;
               }
               for(int x=-1;x<=1;x++)
               {
                  for(int y=-1;y<=1;y++)
                  {
                     if(x==0 && y==0)continue;
                     if(i+x<0 || i+x>=row || j+y<0 || j+y>=col)continue;
                     if(cell[i+x][j+y]=='*')output[i][j]++;
                  }
               }
            }
         }
         if(caseNumber!=1)
         {
            writeLine();
         }
         writeLine("Field #"+caseNumber+":");
         for(int i=0;i<row;i++)
         {
            String s=new String(output[i]);
            writeLine(s);
         }
         caseNumber++;
      }
   }
}

//Powered by myself
User avatar
dttri
New poster
 
Posts: 3
Joined: Thu Apr 05, 2007 7:13 pm
Location: Vietnam

Postby dttri » Sun May 13, 2007 6:33 pm

I copy my Java code above and translate it into C++ and I got Accepted. Don't know why the Java version doesn't work. I think the Java judge here is not well supported. And I don't know why UVA use GCJ instead of Java from Sun?
User avatar
dttri
New poster
 
Posts: 3
Joined: Thu Apr 05, 2007 7:13 pm
Location: Vietnam

Postby Jan » Sun May 13, 2007 10:19 pm

Test the cases. If your code passes then post your code.

Input:
Code: Select all
5 5
*****
*...*
*.*.*
*...*
*****
4 4
****
*..*
*..*
****
0 0

Output:
Code: Select all
Field #1:
*****
*646*
*4*4*
*646*
*****

Field #2:
****
*55*
*55*
****

Hope these help.
Ami ekhono shopno dekhi...
HomePage
Jan
Guru
 
Posts: 1334
Joined: Wed Jun 22, 2005 10:58 pm
Location: Dhaka, Bangladesh

Postby Fuad Hassan EWU » Tue Jul 17, 2007 9:14 pm

simple problem,simple code, but getting WA. where is the bug? plz tell me.
thanks

Code: Select all
#include<iostream>
#include<stdio.h>

using namespace std;

int main()
{
   int m,n,i,j,count,flag=0,field=1;
   char a[109][109];

   while(cin>>m>>n)
   {
       if(m==0&&n==0)
          break;
       if(flag==1)
          cout<<endl;

       for(i=0;i<m;i++)
          for(j=0;j<n;j++)
             cin>>a[i][j];

             cout<<"Field #"<<field<<":"<<endl;
         
          for(i=0;i<m;i++)
          {
             for(j=0;j<n;j++)
             {
                count=0;
              if(a[i][j]!='*')
              {
               
                    if((a[i][j-1]=='*')&&j!=0)
                            count++;
                      if((a[i-1][j-1]=='*')&&i!=0&&j!=0)
                       count++;
                   if((a[i-1][j]=='*')&&i!=0)
                      count++;
                   if((a[i-1][j+1]=='*')&&i != 0 && j != n)
                      count++;
                   if((a[i][j+1]=='*')&& j != n )
                      count++;
                   if((a[i+1][j+1]=='*')&& i != m && j != n )
                      count++;
                   if((a[i+1][j]=='*')&& i != m )
                      count++;
                   if((a[i+1][j-1]=='*')&& i != m && j != 0 )
                      count++;
                   cout<<count;
                  }
              else cout<<"*";
             
             }
             cout<<endl;
          }
          field++;
       flag=1;
   }
return 0;
   }


Eagle er moto daana meley urbo
User avatar
Fuad Hassan EWU
New poster
 
Posts: 38
Joined: Tue Jul 17, 2007 3:21 pm
Location: East West University

PreviousNext

Return to Volume CI

Who is online

Users browsing this forum: No registered users and 1 guest