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

Post by brianfry713 » Thu Nov 14, 2013 10:28 pm

There must be an empty line between field outputs. You're printing an extra blank line at the end.
Check input and AC output for thousands of problems on uDebug!

venkikumar.m
New poster
Posts: 6
Joined: Tue Nov 12, 2013 5:57 pm

Re: 10189 - Minesweeper

Post by venkikumar.m » Mon Nov 18, 2013 6:37 am

I changed the formatting once again...But still shows WA....i don't think so bug is in formatting ..... may be my algo...

Code: Select all

#include<iostream>
using namespace std;
int main()
{
    int n,m,i,j,x=0;
    cin>>n>>m;
    while(n&&m)
    {
        x++;
        char **a=new char*[n];
        for(i=0;i<n;i++)
            a[i]=new char[m];
        char **b=new char*[n];
        for(i=0;i<n;i++)
            b[i]=new char[m];
        for(i=0;i<n;i++)
            for(j=0;j<m;j++)
            {
                cin>>a[i][j];
                b[i][j]=a[i][j];
            }
/*        for(i=0;i<n;i++)
        {
            for(j=0;j<m;j++)
                cout<<b[i][j]<<" ";
            cout<<"\n";
        }
*/
       for(i=0;i<n;i++)
        {
            for(j=0;j<m;j++)
            {
                if(a[i][j]=='*')
                {
                    b[i][j]='*';
                    if((i-1>=0)&&(j-1>=0))
                    {
                        if(b[i-1][j-1]>='0')
                            b[i-1][j-1]+=1;
                        else if(b[i-1][j-1]=='.')
                            b[i-1][j-1]='1';
                    }
                    if((i-1>=0)&&(j>=0))
                    {
                        if(b[i-1][j]>='0')
                            b[i-1][j]+=1;
                        else if(b[i-1][j]=='.')
                           b[i-1][j]='1';
                    }
                    if((i-1>=0)&&(j+1<m))
                    {
                        if(b[i-1][j+1]>='0')
                            b[i-1][j+1]+=1;
                        else if(b[i-1][j+1]=='.')
                            b[i-1][j+1]='1';
                    }
                    if((i<n)&&(j+1<m))
                    {
                        if(b[i][j+1]>='0')
                            b[i][j+1]+=1;
                        else if(b[i][j+1]=='.')
                            b[i][j+1]='1';
                    }
                    if((i+1<n)&&(j+1<m))
                    {
                        if(b[i+1][j+1]>='0')
                            b[i+1][j+1]+=1;
                        else if(b[i+1][j+1]=='.')
                            b[i+1][j+1]='1';
                    }
                    if((i+1<n)&&(j<m))
                    {
                        if(b[i+1][j]>='0')
                            b[i+1][j]+=1;
                        else if(b[i+1][j]=='.')
                            b[i+1][j]='1';
                    }
                    if((i+1<n)&&(j-1>=0))
                    {
                        if(b[i+1][j-1]>='0')
                            b[i+1][j-1]+=1;
                        else if(b[i+1][j-1]=='.')
                            b[i+1][j-1]='1';
                    }
                    if((i>=0)&&(j-1>=0))
                    {
                        if(b[i][j-1]>='0')
                            b[i][j-1]+=1;
                        else if(b[i][j-1]=='.')
                            b[i][j-1]='1';
                    }

                }
            }
        }
        if(x==1)
            cout<<"Field #"<<x<<":";
        else
            cout<<"\n\nField #"<<x<<":";
        for(i=0;i<n;i++)
        {
            cout<<"\n";
            for(j=0;j<m;j++)
            {
                if(b[i][j]=='.')
                    cout<<"0";
                else
                    cout<<b[i][j];
            }
        }
//        cout<<"\n";
        delete a;
        delete b;
        cin>>n>>m;
    }
    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 Nov 18, 2013 10:40 pm

Print a newline char at the end of the last line.
Check input and AC output for thousands of problems on uDebug!

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

Re: 10189 - Minesweeper

Post by brianfry713 » Tue Nov 26, 2013 1:11 am

grvtiwari, don't double post
Check input and AC output for thousands of problems on uDebug!

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

Re: 10189 Minesweeper Run Time Error

Post by brianfry713 » Tue Nov 26, 2013 1:14 am

What if there are more than 101 mines?
Check input and AC output for thousands of problems on uDebug!

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

Re: 10189 Minesweeper Run Time Error

Post by brianfry713 » Tue Nov 26, 2013 11:36 pm

If n and m are 100 then there could be up to 100 * 100 mines. Your rows and cols arrays aren't big enough.
Check input and AC output for thousands of problems on uDebug!

nahin.ruet12
New poster
Posts: 5
Joined: Fri Aug 02, 2013 1:26 pm

10189 - Minesweeper WA

Post by nahin.ruet12 » Mon Dec 02, 2013 9:01 am

i can't understand what is wrong...i followed all instructions properly... but got wrong answer 6 times..! :(
plz help...! :cry:

code removed after Accepted
Last edited by nahin.ruet12 on Tue Dec 03, 2013 7:58 am, edited 1 time in total.

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

Re: 10189 - Minesweeper WA

Post by brianfry713 » Tue Dec 03, 2013 2:57 am

There can be more than 500 mines
Check input and AC output for thousands of problems on uDebug!

nahin.ruet12
New poster
Posts: 5
Joined: Fri Aug 02, 2013 1:26 pm

Re: 10189 - Minesweeper WA

Post by nahin.ruet12 » Tue Dec 03, 2013 7:56 am

thanks got AC...! @brianfry713 :lol:

me33
New poster
Posts: 16
Joined: Wed Feb 19, 2014 10:08 pm

10189 Minesweeper WA....

Post by me33 » Sat Mar 01, 2014 9:20 pm

Plz help..
I think my code works well.

Code: Select all

Got AC.....
Last edited by me33 on Wed Mar 05, 2014 8:47 pm, edited 1 time in total.

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

Re: 10189 Minesweeper WA....

Post by brianfry713 » Sun Mar 02, 2014 5:22 am

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!

me33
New poster
Posts: 16
Joined: Wed Feb 19, 2014 10:08 pm

Re: 10189 Minesweeper WA....

Post by me33 » Wed Mar 05, 2014 8:48 pm

Thanks brianfry713...
got AC.. :P :D :)

ashek.rahman
New poster
Posts: 8
Joined: Mon Mar 10, 2014 8:18 am

Re: 10189 Minesweeper WA....

Post by ashek.rahman » Mon Mar 10, 2014 8:23 am

I got Wrong answer. But I tested all test cases. Please help me.

Code: Select all

#include <iostream>

using namespace std;

int main()
{
    long long int n, m, t, s[100][100];
    char f[100][100];
    t = 1;
    while (cin >> n >> m && n!=0 && m!=0){
        //cout << n << " " << m << endl;
        if (t>1)
            cout << endl;
        for (long long int i=0; i<n; i++){
            for (long long int j=0; j<m; j++){
                cin >> f[i][j];
            }
        }
        for (long long int i=0; i<n; i++){
            for (long long int j=0; j<m; j++){
                s[i][j] = 0;
            }
        }
        for (long long int i=0; i<n; i++){
            for (long long int j=0; j<m; j++){
                if (f[i][j]=='*'){
                    if (i-1>=0 && j-1>=0){
                        s[i-1][j-1]++;
                        //cout << i << " " << j << " " << i-1 << " " << j-1 << endl;
                    }
                    if (i-1>=0 && j>=0){
                        s[i-1][j]++;
                        //cout << i << " " << j << " " << i-1 << " " << j << endl;
                    }
                    if (i-1>=0 && j+1<=m){
                        s[i-1][j+1]++;
                        //cout << i << " " << j << " " << i-1 << " " << j+1 << endl;
                    }
                    if (i>=0 && j-1>=0){
                        s[i][j-1]++;
                        //cout << i << " " << j << " " << i << " " << j-1 << endl;
                    }
                    if (i>=0 && j+1<=m){
                        s[i][j+1]++;
                        //cout << i << " " << j << " " << i << " " << j+1 << endl;
                    }
                    if (i+1<=n && j-1>=0){
                        s[i+1][j-1]++;
                        //cout << i << " " << j << " " << i+1 << " " << j-1 << endl;
                    }
                    if (i+1<=n && j>=0){
                        s[i+1][j]++;
                        //cout << i << " " << j << " " << i+1 << " " << j << endl;
                    }
                    if (i+1<=n && j+1<=m){
                        s[i+1][j+1]++;
                        //cout << i << " " << j << " " << i+1 << " " << j+1 << endl;
                    }
                }
            }
        }
        cout << "Field #" << t << ":" << endl;
        t++;
        for (long long int i=0; i<n; i++){
            for (long long int j=0; j<m; j++){
                if (f[i][j]=='*')
                    cout << '*';
                else
                    cout <<s[i][j];
            }
            cout << endl;
        }
    }
    return 0;
}

biplabks
New poster
Posts: 7
Joined: Sun Mar 09, 2014 11:20 am

Re: 10189 Minesweeper - WA

Post by biplabks » Mon Mar 10, 2014 11:23 am

I don't know...why i am getting WA.
can anybody help pls?

got accepted...thank u..
Last edited by biplabks on Mon Mar 10, 2014 9:31 pm, edited 1 time in total.

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

Re: 10189 Minesweeper - WA

Post by brianfry713 » Mon Mar 10, 2014 8:05 pm

Input:

Code: Select all

13 100
.*..*..*..**.*.**..***.*.****.***.*..*..***..**.***.****.*.***.****.**..*..**.***.*.***..****...*...
***.**..****.***.**..****.....***...*.***..*****..****..*.***.....**......*...*.***...**...*....****
*.**.**.***...*...**.*..*...**..**...*...*...*..****..*..*..*........*...**..**.*.**.***..**.*....*.
**...*.****...*.***.*.**.*...*.*..**...******..****.........*.**.*..*.*.*..**...***********.***....*
..*..*****.*.*.*..***.***.**.*.**.*.*.****.*.....**...***.****.******.....*...***.***.*...***..***.*
..*..*..***....*.**.*.....*..**.*..**....**..**...**.*******..*..**..*..**.*.**.*.****.*.*..*...*..*
*.*..**..****.****.**.........*.**.*..***...***.**.......*.**.*.******..***...**.**.*..***..***.*.*.
*.***.**..*.*....*.*...*.****.**...*.***..**...**..*....******..*.*.*.**..**.*.**..**...****.**.*..*
**.***....***.*..*....***.**.*.*..**.**..*.*****.**.*.**...**..*.**.*.****...*...*....*..**.*.***...
***..**..*.*..*...***.*...*.**......**....***.**...*****..**..*..*******...*.....***..*.*.**..*....*
.*...**.****..***.*..****.****.*****..***...***.*...*****....***.....**..*.****.**.*.*.*....****.**.
......***.***..**.**.**...*.***.**.*...*......**..***.*.*...**.***.***.*******..****..**.**.*.*.***.
.***.*...*.*.*..*******.*....*...*.*..*.**.....*...**.*..*....*.***.*..**.****.***..**.*.....*.....*
0 0
AC output:

Code: Select all

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
1***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*
Check input and AC output for thousands of problems on uDebug!

Post Reply

Return to “Volume 101 (10100-10199)”