Minesweeper

General topic about Valladolid Online Judge

Moderator: Board moderators

Minesweeper

Postby white_snake » Sun Feb 12, 2012 1:01 pm

Something is weird with the UVA compiler and you definitely need to fix it. I get Compilation Error and on my computer it compiles and runs perfectly on my computer.
Anyway, here is the code.
Thank you very much for your time. :)
Code: Select all
#include <stdio.h>
#include <stdlib.h>

int adjecant_mines(int i, int j, int upper, int lower);
char grid[1000][1000];

void print_grid(int n, int m);
void mark_grid(int n, int m);
void reset_grid(void);
int main(void)
{
   int n,m,i,j,field = 1;

   while(scanf("%d %d",&n,&m)!=EOF){

      getchar();
      if((n==0)&&(m==0))
         break;
   reset_grid();   
   for(i=0;i<n;i++)
   {
      for(j=0;j<m;j++)
      {
         scanf("%c",&grid[i][j]);
      }
      getchar();
   }
   printf("Field #%d:\n",field);
   
   mark_grid(n,m);
   print_grid(n,m);
   field++;
   }
   return 0;
}
int adjecant_mines(int i, int j, int upper, int lower)
{
   int res  = 0;
   int n,m,t1,t2;
   for(n=-1;n<=1;n++)
   {
    
      for(m=-1;m<=1;m++)
      {
         t1 = i + n;
         t2 = j + m;
         if(grid[t1][t1]=='*' && t1 > -1 && t2 > -1 && t1 < upper && t2 < lower)
            res ++ ;
      }
   }
   return res;
}

void print_grid(int n, int m)
{
   int i,j;
   for(i=0;i<n;i++)
   {
      for(j=0;j<m;j++)
      {
         printf("%c",grid[i][j]);
      }
      printf("\n");
   }
}
void mark_grid(int n, int m) //Mark the grid so that each field gets the value of adjecant mines around it.
{
   int i,j;
   for(i=0;i<n;i++)
   {
      for(j=0;j<m;j++)
      {
         if(grid[i][j]=='.')
            grid[i][j] = (char)((int)'0' + adjecant_mines(i,j,n,m));
      }
   }
}
void reset_grid(void)
{
   int i,j;
   for(i=0;i<1000;i++)
   {
      for(j=0;j<1000;j++)
      {
         grid[i][j] = '.';
      }
   }
}
white_snake
New poster
 
Posts: 3
Joined: Sun Feb 12, 2012 12:57 pm

Re: Minesweeper

Postby mike65 » Mon Feb 13, 2012 9:46 am

Really?
Try asking to experter on another forum...
mike65
New poster
 
Posts: 2
Joined: Mon Feb 13, 2012 9:41 am

Re: Minesweeper

Postby brianfry713 » Mon Feb 13, 2012 10:39 pm

This compiles in C++.
If you use the // comments you need to use C++, ANSI C only supports /* comments */.
adjecant should be spelled adjacent.
brianfry713
Guru
 
Posts: 1861
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA


Return to General

Who is online

Users browsing this forum: No registered users and 1 guest