Page 24 of 28

Re: 10189 - Minesweeper

Posted: Thu Nov 14, 2013 10:28 pm
by brianfry713
There must be an empty line between field outputs. You're printing an extra blank line at the end.

Re: 10189 - Minesweeper

Posted: Mon Nov 18, 2013 6:37 am
by venkikumar.m
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;
}

Re: 10189 - Minesweeper

Posted: Mon Nov 18, 2013 10:40 pm
by brianfry713
Print a newline char at the end of the last line.

Re: 10189 - Minesweeper

Posted: Tue Nov 26, 2013 1:11 am
by brianfry713
grvtiwari, don't double post

Re: 10189 Minesweeper Run Time Error

Posted: Tue Nov 26, 2013 1:14 am
by brianfry713
What if there are more than 101 mines?

Re: 10189 Minesweeper Run Time Error

Posted: Tue Nov 26, 2013 11:36 pm
by brianfry713
If n and m are 100 then there could be up to 100 * 100 mines. Your rows and cols arrays aren't big enough.

10189 - Minesweeper WA

Posted: Mon Dec 02, 2013 9:01 am
by nahin.ruet12
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

Re: 10189 - Minesweeper WA

Posted: Tue Dec 03, 2013 2:57 am
by brianfry713
There can be more than 500 mines

Re: 10189 - Minesweeper WA

Posted: Tue Dec 03, 2013 7:56 am
by nahin.ruet12
thanks got AC...! @brianfry713 :lol:

10189 Minesweeper WA....

Posted: Sat Mar 01, 2014 9:20 pm
by me33
Plz help..
I think my code works well.

Code: Select all

Got AC.....

Re: 10189 Minesweeper WA....

Posted: Sun Mar 02, 2014 5:22 am
by brianfry713
There must be an empty line between field outputs. Don't print an extra blank line at the end.

Re: 10189 Minesweeper WA....

Posted: Wed Mar 05, 2014 8:48 pm
by me33
Thanks brianfry713...
got AC.. :P :D :)

Re: 10189 Minesweeper WA....

Posted: Mon Mar 10, 2014 8:23 am
by ashek.rahman
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;
}

Re: 10189 Minesweeper - WA

Posted: Mon Mar 10, 2014 11:23 am
by biplabks
I don't know...why i am getting WA.
can anybody help pls?

got accepted...thank u..

Re: 10189 Minesweeper - WA

Posted: Mon Mar 10, 2014 8:05 pm
by brianfry713
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*