Page 5 of 28

Posted: Sun Sep 26, 2004 7:08 am
by Ghust_omega
Hi rs6 genaraly you have to ouput the result while you read the input, no for all the problems,that means thar read one case and ouput for that case , try with this I/O

Code: Select all

6 10
****..**.*
.**.....*.
**...****.
..***.*.**
**.*..*.*.
*..*...***

4 3
.*.
***
.*.
*.*

1 2
*.

7 1
.
.
.
.
*
*
.

7 6
...*..
..**..
.***.*
...*..
***.*.
******
****.*

5 10
*.**..*.**
*...*.*.*.
*.****...*
.*.....*.*
****..**.*

8 8
*.*****.
.**.*..*
**......
.***..*.
*.*.*..*
*..*...*
**..*..*
*....*.*

1 2
..

4 10
....*.....
*.....**..
****.*..**
**.***..*.

6 4
....
..**
.*.*
...*
*...
*.**

5 2
**
**
.*
*.
**

7 8
......*.
*......*
*.*...*.
...***..
*..***..
*..*.***
*.**..*.

8 7
..*...*
......*
.***...
*..*...
**.****
*..*..*
.**...*
...*...

9 6
****..
*.**.*
**.*.*
*.**.*
****..
****..
**.*..
.**..*
..****

1 4
*.**

7 9
..*..*...
.......*.
.*.*.****
...*...*.
**.**.**.
.....*..*
****.***.

9 3
***
.*.
**.
*..
*..
***
*..
***
**.

8 5
**...
.****
*.***
***..
..**.
..**.
....*
...**

2 10
..****.***
....***.**

5 1
*
*
.
*
.
0 0
This is the ouput from my AC(accepted) code:

Code: Select all

Field #1:
****11**3*
5**32356*3
**543****4
45***5*7**
**5*43*6*5
*33*212***

Field #2:
3*3
***
4*4
*3*

Field #3:
*1

Field #4:
0
0
0
1
*
*
1

Field #5:
013*20
13**41
1***4*
356*42
***6*3
******
****5*

Field #6:
*3**23*4**
*546*5*4*4
*4****334*
4*65434*5*
****11**4*

Field #7:
*4*****2
4**5*43*
**642222
4***22*2
*5*5*23*
*53*323*
**22*24*
*3112*3*

Field #8:
00

Field #9:
1101*22210
*43333**32
****5*44**
**5***22*3

Field #10:
0122
12**
1*5*
223*
*333
*3**

Field #11:
**
**
4*
*4
**

Field #12:
110001*2
*311023*
*3*333*2
233***31
*23***52
*44*6***
*3**33*3

Field #13:
01*102*
134312*
2***211
*56*532
**4****
*55*45*
2**322*
123*111

Field #14:
****31
*7**5*
**6*6*
*7**5*
****41
****30
**7*31
3**55*
13****

Field #15:
*2**

Field #16:
01*11*211
1232335*3
1*3*3****
335*546*4
**3**3**3
45545*65*
****3***2

Field #17:
***
5*4
**2
*41
*52
***
*74
***
**3

Field #18:
**432
4****
*7***
***63
25**2
02**3
0135*
001**

Field #19:
01****4***
0124***4**

Field #20:
*
*
2
*
1
Hope its Helps
Keep posting!! :D

Posted: Sun Sep 26, 2004 7:48 am
by rs6
Thnx ghust... ive found a critical error with the index n and m...... but stills WA :( I can't find another error... please help.... Both outputs are now the same

[cpp]
#include <stdio.h>


void imprime(int resultante[110][110], int n, int m, int count)
{


int i,j;

printf("Field #%d:\n", count);
for(i=0;i<n;i++)
{
for(j=0;j<m;j++)
if(resultante[j]<9)
printf("%d", resultante[j]);

else
printf("*");

if(i!=n-1)
printf("\n");
}

}






void leeDatos()
{

int count=1;
int n, m,i,j;
char map;
int resultante[110][110];



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



for(i=0;i<n;i++)
for(j=0;j<m;j++)
resultante[j]=0;

scanf("\n");

for(i=0;i<n;i++)
{
for(j=0;j<m;j++)
{
scanf("%c", &map);
if(map=='*')
{
resultante[j]=9;

if(i-1>=0)
{
if(j-1>=0)
resultante[i-1][j-1]++;

if(j+1<m)
resultante[i-1][j+1]++;

resultante[i-1][j]++;

}
if(j-1>=0)
resultante[j-1]++;

if(j+1<m)
resultante[j+1]++;

if(i+1<n)
{
if(j-1>=0)
resultante[i+1][j-1]++;

if(j+1<m)
resultante[i+1][j+1]++;

resultante[i+1][j]++;
}


}

}
if(i<n-1)
scanf("\n");

}

if(count>1)
printf("\n\n");
imprime(resultante,n,m,count);
count++;



}


}

int main()
{
leeDatos();


return 0;

}
[/cpp]

The ouput, on the end... have new lines?

10189 WA - Banging my head against the desk.

Posted: Fri Oct 08, 2004 4:50 pm
by artlogic
Can anyone offer me any insight as to why I am getting a WA with my code - I just need a fresh set of eyes. I must be missing something simple:

Code: Select all

/* @JUDGE_ID: XXXXXX 10189 C++ "" */

#include <iostream>
#include <string>

using namespace std;

void printsweep(string cur, string prev1, string prev2, int m) {
  int minecount = 0;

  for (int i = 0; i < m; i++) {
      if (prev1[i] == '*') cout << "*";
      else {
          if (prev2 != "") {
              if (i > 0) minecount += (prev2[i-1] == '*');
              minecount += (prev2[i] == '*');
              if (i < m) minecount += (prev2[i+1] == '*');
          }

          if (i > 0) minecount += (prev1[i-1] == '*');
          if (i < m) minecount += (prev1[i+1] == '*');

          if (cur != "") {
              if (i > 0) minecount += (cur[i-1] == '*');
              minecount += (cur[i] == '*');
              if (i < m) minecount += (cur[i+1] == '*');
          }
          cout << minecount;
          minecount = 0;
      }
  }
  cout << endl;
}

int main() {
  int n, m, f = 1;
  string cur, prev1 = "", prev2 = "";

  cin >> n >> m;

  while (n != 0) {
      cout << "Field #" << f << ":" << endl;

      for (int i = 0; i < n; i++) {
          cin >> cur;
          if (i > 0) printsweep(cur, prev1, prev2, m);
          prev2 = prev1;
          prev1 = cur;
      }

      printsweep("", prev1, prev2, m);
	   cout << endl;

      prev1 = prev2 = "";
	   f++;

      cin >> n >> m;
  }
  return 0;
}
Thanks!

Posted: Fri Oct 08, 2004 7:04 pm
by Ghust_omega
Hi !! artlogic this some I/O http://online-judge.uva.es/board/viewto ... c97d9316a5
maybe you can test
Hope it Helps
Keep posting !! :D

Posted: Fri Oct 08, 2004 9:10 pm
by artlogic
Unfortunately I had seen that post and tested already... the ONLY difference is that my output has two extra crlf pairs - one to end my last line, and one to seperate the next field. I would think that if this were the problem I would be getting something more like PE. Thanks for your help though - does anyone have any other ideas?

Posted: Sat Oct 09, 2004 7:32 pm
by artlogic
programming challenges accepted this code with one minor change - I just just trying to understand why I am still getting WA

NEW CODE:

Code: Select all

/* @JUDGE_ID: 51203TX 10189 C++ "" */

#include <iostream>
#include <string>

using namespace std;

void printsweep(string cur, string prev1, string prev2, int m) {
  int minecount = 0;

  for (int i = 0; i < m; i++) {
      if (prev1[i] == '*') cout << "*";
      else {
          if (prev2 != "") {
              if (i > 0) minecount += (prev2[i-1] == '*');
              minecount += (prev2[i] == '*');
              if (i < m) minecount += (prev2[i+1] == '*');
          }

          if (i > 0) minecount += (prev1[i-1] == '*');
          if (i < m) minecount += (prev1[i+1] == '*');

          if (cur != "") {
              if (i > 0) minecount += (cur[i-1] == '*');
              minecount += (cur[i] == '*');
              if (i < m) minecount += (cur[i+1] == '*');
          }
          cout << minecount;
          minecount = 0;
      }
  }
  cout << endl;
}

int main() {
  int n, m, f = 1;
  string cur, prev1 = "", prev2 = "";

  cin >> n >> m;

  while (n != 0) {
      cout << "Field #" << f << ":" << endl;

      for (int i = 0; i < n; i++) {
          cin >> cur;
          if (i > 0) printsweep(cur, prev1, prev2, m);
          prev2 = prev1;
          prev1 = cur;
      }

      printsweep("", prev1, prev2, m);

      prev1 = prev2 = "";
      f++;

      cin >> n >> m;
      if (n != 0) cout << endl;
  }
  return 0;
} 
Any suggestions or help would be greatly appreciated.

GRR!

Posted: Sun Oct 10, 2004 2:16 am
by asterisk
GRR!!
input file has the input up there, in the page ^


look at this:

Code: Select all

------------------------------------------------------------------------------
$ gcc -o 99 code.c
$ ./99 < input 
Field #1:
****11**3*
5**32356*3
**543****4
45***5*7**
**5*43*6*5
*33*212***

Field #2:
3*3
***
4*4
*3*

Field #3:
*1

Field #4:
0
0
0
1
*
*
1

Field #5:
013*20
13**41
1***4*
356*42
***6*3
******
****5*

Field #6:
*3**23*4**
*546*5*4*4
*4****334*
4*65434*5*
****11**4*

Field #7:
*4*****2
4**5*43*
**642222
4***22*2
*5*5*23*
*53*323*
**22*24*
*3112*3*

Field #8:
00

Field #9:
1101*22210
*43333**32
****5*44**
**5***22*3

Field #10:
0122
12**
1*5*
223*
*333
*3**

Field #11:
**
**
4*
*4
**

Field #12:
110001*2
*311023*
*3*333*2
233***31
*23***52
*44*6***
*3**33*3

Field #13:
01*102*
134312*
2***211
*56*532
**4****
*55*45*
2**322*
123*111

Field #14:
****31
*7**5*
**6*6*
*7**5*
****41
****30
**7*31
3**55*
13****

Field #15:
*2**

Field #16:
01*11*211
1232335*3
1*3*3****
335*546*4
**3**3**3
45545*65*
****3***2

Field #17:
***
5*4
**2
*41
*52
***
*74
***
**3

Field #18:
**432
4****
*7***
***63
25**2
02**3
0135*
001**

Field #19:
01****4***
0124***4**

Field #20:
*
*
2
*
1

$


-------------------------------
LOOK AT THIS!
it gives me a WA!!!
and the output is right! any ideas?

ill give you the code:

[c]
#include <stdio.h>

int main(void) {
char field[100][100],ch;
int a,b;
int i,j;
int m,n; /* m - linha; n - colunas */
int num=0;

while(scanf("%d %d",&m,&n) == 2 && (m != 0) || (n != 0)) {
++num;
for (i=0;i<m;i++)
for(j=0;j<=n;j++)
field[j] = '0';



for(i=0;i<m;i++) {
for(j=0;j<=n;j++) {
if ((ch = getchar()) == '.')
continue;
else if (ch == '*') {
field[j] = ch;
a = i-1;
while (a<0)
++a;
for(;a<=i+1;a++) {
b = j-1;
while (b<0)
++b;
for(;b<=j+1;b++) {
if (field[a] != '*')
(int) ++field[a];
}
}
}
else if (ch == '\n')
field[j] = ch;
}
}
printf("Field #%d:\n",num);
for (i=0;i<m;i++) {
for(j=1;j<=n;j++)
printf("%c",field[j]);

printf("\n");
}
printf("\n");

}
}[/c][/code]

Posted: Sun Oct 10, 2004 6:19 am
by Ghust_omega
Hi !! asterisk I just change the indes of array
fo 100 to 105 and gives AC (P.E.) you have
to see how to avoid that and remove your code
Hope it Helps
Keep posting

Re: 10189 WA - Banging my head against the desk.

Posted: Wed Oct 13, 2004 8:16 am
by jambon_vn
This problem is not hard but anyone know the way to speed up the program. The fastest record is 0.000s. How did he do? :(

10189...With WA...

Posted: Sat Oct 23, 2004 5:17 am
by Wei
I don't know where is wrong...
I tried to do with some datas~~~but the judge still gave WA~
Could somebody help me with this???

[c]#include <stdio.h>
#include <stdlib.h>

int main(void)
{
unsigned long n[105][105]={0},i,j,a,b,co,lead=1;
char ch[0];
scanf("%lu %lu",&a,&b);
while(a!=0&&b!=0)
{
int n[105][105]={0};
co=0;
scanf("%c",&ch);
for(i=1;i<=a;i++)
{
for(j=1;j<=b;j++)
{
scanf("%c",&ch);
if(ch[0]==42)
n[j]=1;
if(ch[0]==46)
n[j]=0;
}
scanf("%c",&ch);
}
printf("Field #%lu:\n",lead);
for(i=1;i<=a;i++)
{
for(j=1;j<=b;j++)
{
co=0;
if(n[j]==1)
{printf("*");}
else
{
if(n[i-1][j-1]==1)
co++;
if(n[j-1]==1)
co++;
if(n[i+1][j-1]==1)
co++;
if(n[i-1][j]==1)
co++;
if(n[i+1][j]==1)
co++;
if(n[i-1][j+1]==1)
co++;
if(n[j+1]==1)
co++;
if(n[i+1][j+1]==1)
co++;
printf("%lu",co);
}
}
printf("\n");
}
printf("\n");
scanf("%lu %lu",&a,&b);
lead++;
}
return 0;
}
[/c]

Posted: Sat Oct 23, 2004 8:05 pm
by Mohammad Mahmudur Rahman
Hi,
I just changed the following line from your code

Code: Select all

 char ch[0];

to

Code: Select all

 char ch; 
as I coudln't compile it (Which compiler did you use?) & then got Accepted (PE). Make sure.

Posted: Sun Oct 24, 2004 4:45 am
by Wei
Well~~Thx for the advice...
Now~~I got an AC(P.E.)...and I know where is wrong~~~
I use the Dev.C++...

Posted: Mon Oct 25, 2004 6:05 pm
by smilejfu
I've tried many datas
And all got correct.
Or is my way wrong?
Here is my code: (say thanks to you first :D )

Code: Select all


#include <stdio.h> 
#include <stdlib.h> 
int main(void) 
{ 
    int m,n; 
    char **map,ch; 
    int i,j,total,count=1,a,b; 

    while(scanf("%d %d",&n,&m)) 
     { 
      if(m==0&&n==0) break; 
      map=(char **)malloc((n+2)*sizeof(char *)); 
      for(i=0;i<(n+2);i++) 
        map[i]=(char *)malloc((m+2)*sizeof(char)); 

      for(i=1;i<=n;i++) 
         for(j=1;j<=m;j++) 
           scanf(" %c", &map[i][j]); 

      printf("Field #%d:\n",count++); 
      for(i=1;i<=n;i++) 
        { 
         for(j=1;j<=m;j++) 
          { 
           if(map[i][j]=='*')  printf("*"); 
           else 
             { 
              total=0; 
              if(map[i-1][j-1]=='*')  total++; 
              if(map[i-1][j  ]=='*')  total++; 
              if(map[i-1][j+1]=='*')  total++; 
              if(map[i  ][j-1]=='*')  total++; 
              if(map[i  ][j+1]=='*')  total++; 
              if(map[i+1][j-1]=='*')  total++; 
              if(map[i+1][j  ]=='*')  total++; 
              if(map[i+1][j+1]=='*')  total++; 
              printf("%d",total); 
             } 
          } 
         printf("\n"); 
       } 
      printf("\n"); 

      for(i=0;i<(n+2);i++) 
        free(map[i]); 
      free(map); 
     } 
    return 0; 
} 
 

10189 - Minesweeper

Posted: Sun Jul 10, 2005 5:26 pm
by Fuad Hassan_IIUC(DC)
i just can't believe that i am getting WA!!!! i know i am making simple mistakes but can't find out where the mistake is :evil:
#include<stdio.h>
#include<iostream.h>
int main()
{
char str[50][50];
int i,j,count,a,b,field=1;
while(cin>>a>>b)
{
if(a==0&&b==0)
break;
for(i=0;i<a;i++)
{
for(j=0;j<b;j++)
{
cin>>str[j];

}
}
printf("Field #%d:\n",field);
for(i=0;i<a;i++)
{

for(j=0;j<b;j++)
{
count=0;
if(str[j]=='*')
cout<<"*";
else
{

if(str[j-1]=='*')
count++;
if(str[j+1]=='*')
count++;
if(str[i-1][j]=='*')
count++;
if(str[i+1][j]=='*')
count++;
if(str[i-1][j-1]=='*')
count++;
if(str[i+1][j-1]=='*')
count++;
if(str[i-1][j+1]=='*')
count++;
if(str[i+1][j+1]=='*')
count++;
printf("%d",count);
}
}
printf("\n");
}
field++;
}
return 0;
} :evil:

Posted: Sun Jul 10, 2005 5:30 pm
by Fuad Hassan_IIUC(DC)
actually when i submitted this problem i made the size of str[105][105]
my fault is in another place