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

Shahidul.CSE
Experienced poster
Posts: 148
Joined: Sun Jul 13, 2014 4:32 am
Location: Rangpur, Bangladesh

Re: 10189 - Minesweeper

Post by Shahidul.CSE » Tue Aug 12, 2014 12:03 pm

Code: Select all

Rempved after accepted! :D 
Last edited by Shahidul.CSE on Fri Aug 15, 2014 5:10 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

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

Re: 10189 - Minesweeper

Post by brianfry713 » Wed Aug 13, 2014 12:24 am

Always print a newline char at the end of the last line.

Post your full updated code if you still need help.
Check input and AC output for thousands of problems on uDebug!

Shahidul.CSE
Experienced poster
Posts: 148
Joined: Sun Jul 13, 2014 4:32 am
Location: Rangpur, Bangladesh

Re: 10189 - Minesweeper

Post by Shahidul.CSE » Thu Aug 14, 2014 1:50 pm

Removed after got Accepted !!
Last edited by Shahidul.CSE on Fri Aug 15, 2014 4:58 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

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

Re: 10189 - Minesweeper

Post by brianfry713 » Fri Aug 15, 2014 12:04 am

The first code is correct as far as newlines go.

On line 25 instead of:
if(j != m) {
change it to something like:
if(j != m - 1) {

Apply similar changes to other lines in your code.
Check input and AC output for thousands of problems on uDebug!

fresher96
New poster
Posts: 25
Joined: Wed Sep 03, 2014 8:50 am

Re: 10189 - Minesweeper

Post by fresher96 » Thu Sep 04, 2014 10:18 am

thanks very much guys !
i'm new for in the ACM problems
in the real contest is it the same that they give wrong answer for a single stupid blank line at the end !!!
or it's just here because of the online judge ?

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

Re: 10189 - Minesweeper

Post by brianfry713 » Thu Sep 04, 2014 6:59 pm

Read the rules of the contest you are entering.
Check input and AC output for thousands of problems on uDebug!

Ishtiaq11
New poster
Posts: 2
Joined: Sat Sep 27, 2014 8:11 pm

Re: 10189 - Minesweeper

Post by Ishtiaq11 » Sat Sep 27, 2014 10:10 pm

>>>>>>>>>>Why Time Limit ? :cry: Please help.


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

int main()
{

int row,col,cnt = 0;
while(true)
{
cin >> row >> col ;
if(row == 0 && col == 0) break;
cnt++;
if(cnt > 1) cout << "\n";
int field[102][102] = {0};

for(int i = 0; i < row; i++){
for(int j =0; j < col; j++){
char temp;
cin >> temp;
if(temp == '*'){
field[j] = -1;

if(field[i-1][j-1] != -1) field[i-1][j-1]++;//lower row
if(field[i-1][j] != -1) field[i-1][j]++;//lower row
if(field[i-1][j+1] != -1) field[i-1][j+1]++;//lower row

if(field[j-1] != -1) field[j-1]++;//that row
if(field[j+1] != -1) field[j+1]++;//that row

if(field[i+1][j-1] != -1) field[i+1][j-1]++;//upper row
if(field[i+1][j] != -1) field[i+1][j]++;//upper row
if(field[i+1][j+1] != -1) field[i+1][j+1]++;//upper row
}
}
}

cout << "Field #" << cnt << ":\n" ;
for(int i = 0; i < row; i++){
for(int j =0; j < col; j++){
if(field[j] == -1) cout << '*' ;
else cout << field[j];
}
cout << "\n" ;
}
}

return 0;
}

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

Re: 10189 - Minesweeper

Post by brianfry713 » Mon Sep 29, 2014 8:18 pm

If i or j equals 0 then you shouldn't read or write to field[j - 1].
Check input and AC output for thousands of problems on uDebug!

mohdali231993
New poster
Posts: 11
Joined: Sun Nov 09, 2014 6:46 pm

Re: 10189 - Minesweeper

Post by mohdali231993 » Sun Nov 09, 2014 6:56 pm

Code: Select all

#include <iostream>
using namespace std;
int main()
{
 int a,b,i,j,count=0;int arr[101][101];char carr[101][101];
 while(1)
 {cin>>a>>b;
  
  if(!a && !b)
   break;
  count++;if(count>1){cout<<endl;}
  for(i=1;i<=a;i++)
  {
   for(j=1;j<=b;j++)
   {
    char c;
    cin>>c;
    carr[i][j]=c;
    if(c==42)
    {
     arr[i-1][j-1]++;
     arr[i][j-1]++;
     arr[i+1][j-1]++;
     arr[i-1][j]++;
     arr[i+1][j]++;
     arr[i-1][j+1]++;
     arr[i][j+1]++;
     arr[i+1][j+1]++;
    }

   }

  }
  cout<<"Field #"<<count<<":"<<endl;
  for(i=1;i<=a;i++)
  {
   for(j=1;j<=b;j++)
   {
    if(carr[i][j]==42)
    cout<<"*";
    else
    cout<<arr[i][j];
   }
  
   cout<<endl;
  }
  
  for(i=0;i<=a+1;i++)
  for(j=0;j<=b+1;j++)
  {arr[i][j]=0;carr[i][j]='.';}

 }

 return 0;
}
Guys help!!!
cannot get around the wa
Last edited by brianfry713 on Mon Nov 10, 2014 11:02 pm, edited 2 times in total.
Reason: Added code blocks

lighted
Guru
Posts: 585
Joined: Wed Jun 11, 2014 9:56 pm
Location: Kyrgyzstan, Bishkek

Re: 10189 - Minesweeper

Post by lighted » Sun Nov 09, 2014 8:11 pm

Use code tags. Increase array limits to

Code: Select all

int arr[110][110];
char carr[110][110];
Don't forget to remove your code after getting accepted. 8)
A person who sees the good in things has good thoughts. And he who has good thoughts receives pleasure from life... Bediuzzaman

mohdali231993
New poster
Posts: 11
Joined: Sun Nov 09, 2014 6:46 pm

Re: 10189 - Minesweeper

Post by mohdali231993 » Sun Nov 09, 2014 8:58 pm

Thanks man :D
But why exactly 110??

lighted
Guru
Posts: 585
Joined: Wed Jun 11, 2014 9:56 pm
Location: Kyrgyzstan, Bishkek

Re: 10189 - Minesweeper

Post by lighted » Mon Nov 10, 2014 3:39 pm

If you make your array arr global or add memset(arr, 0, sizeof(arr)) before each query, it is enough to increase to arr[102][102].

I hope you'll understand why it is exactly 102 yourself. :)
A person who sees the good in things has good thoughts. And he who has good thoughts receives pleasure from life... Bediuzzaman

ehsanulbigboss
New poster
Posts: 32
Joined: Tue Jul 22, 2014 1:17 am

Re: 10189 - Minesweeper

Post by ehsanulbigboss » Wed Dec 03, 2014 3:03 pm

Thanks to lighted
Last edited by ehsanulbigboss on Wed Dec 03, 2014 7:55 pm, edited 2 times in total.

lighted
Guru
Posts: 585
Joined: Wed Jun 11, 2014 9:56 pm
Location: Kyrgyzstan, Bishkek

Re: 10189 - Minesweeper

Post by lighted » Wed Dec 03, 2014 6:53 pm

You don't clear all previous values. Increase it with +1. Because you access to that values when printing results. Or use memset of whole array. :)

Code: Select all

for (i = 0 ; i <= row + 1; i++)
    for (j = 0 ; j <= column + 1; j++)
        array[i][j] = 0;
A person who sees the good in things has good thoughts. And he who has good thoughts receives pleasure from life... Bediuzzaman

Echoless
New poster
Posts: 4
Joined: Fri Dec 05, 2014 3:27 am

Re: 10189 - Minesweeper

Post by Echoless » Fri Dec 05, 2014 3:30 am

Thanks again to lighted.:)
Last edited by Echoless on Fri Dec 05, 2014 5:56 pm, edited 2 times in total.

Post Reply

Return to “Volume 101 (10100-10199)”