Page 2 of 28

Posted: Sun Aug 24, 2003 6:26 pm
by Julien Cornebise
Well, don't care too much about PE, if adding or taking off a newline doesn't solve it. It might be that the judge output has itself a PE compared to the theorical output (it already happened) :)

10189 Why WA?

Posted: Thu Sep 04, 2003 9:20 am
by zilnus
[c]
int main()
{
int i,j,k,l,m,a,b;
int win[200][200];
int nextx[8] = {-1,-1,-1,0,0,1,1,1};
int nexty[8] = {-1,0,1,-1,1,-1,0,1};
char string[150];
int kasus = 1;

while ((i != 0)&&(j != 0))
{
scanf("%d %d",&i,&j);

for (a=0;a<105;a++)
for (b=0;b<105;b++)
win[a] = 0;

for (k=1;k<=i;k++) {
scanf("%s",string);
for (l=0;l<j;l++) {
if (string[l] == '*') win[k][l+1] = -1;
}
}

for (k=1;k<=i;k++){
for (l=1;l<=j;l++){
for (m=0;m<8;m++) {
if (win[k][l] != -1) {
if (win[k + nextx[m] ][l + nexty[m] ] == -1) win[k][l] = win[k][l] + 1;
}
}
}
}

if ((i==0)&&(j==0)) exit(-1);
printf ("Field #%d:\n",kasus);
kasus++;
for (k=1;k<=i;k++) {
for (l=1;l<=j;l++) {
if (win[k][l] == -1) printf ("*");
else printf ("%d",win[k][l]);
}
printf ("\n");
}
}

return 0;
}[/c]

Anyone please help me ? Why wrong answer ???

Posted: Thu Sep 04, 2003 2:52 pm
by titid_gede
hi zilnus... you're from bandung, rite?

looking at the code.. when i == 0 and j == 0, your code doesnt immediately break, but read input first, perhaps it can cause error..

regards,
titid

Posted: Fri Sep 05, 2003 9:35 am
by Joseph Kurniawan
You just have to change the part:
[c]
while ((i != 0)&&(j != 0))
{
scanf("%d %d",&i,&j);
[/c]

with

[c]
while(scanf("%i %i",&i,&j)){
if(!i&&!j) break;
[/c]

That'll solve it (but very possibly with P.E.)!! :wink: :wink:

10189 trouble

Posted: Thu Sep 18, 2003 7:56 pm
by Eva
[cpp]
#include<iostream.h>


bool mnsp[101][101];
int m,n;


inline void set(void)
{
memset(mnsp,0,sizeof(mnsp));
}


int check(int a,int b)
{
int t = 0;

if(mnsp[a-1][b-1] == 1)
t++;
if(mnsp[a-1] == 1)
t++;
if(mnsp[a-1][b+1] == 1)
t++;
if(mnsp[a][b-1] == 1)
t++;
if(mnsp[a][b+1] == 1)
t++;
if(mnsp[a+1][b-1] == 1)
t++;
if(mnsp[a+1] == 1)
t++;
if(mnsp[a+1][b+1] == 1)
t++;

return t;
}



int main()
{
int count = 1;
cin >> m >> n;

while(m || n)
{
set();

cout << "Field #" << count << ':' << endl;


for(int i=1;i<=m;++i)
{
for(int j=1;j<=n;++j)
{
char ch;
cin >> ch;

if(ch == '*')
mnsp[j] = 1;
}
}

for(int i=1;i<=m;++i)
{
for(int j=1;j<=n;++j)
if(mnsp[j] == 0)
cout << check(i,j);
else
cout << '*';

cout << endl;
}

cout << endl;

cin >> m >> n;
count++;
}

return 0;
}[/cpp]

Posted: Fri Sep 19, 2003 12:34 am
by Per
You'll have trouble when the minefield is 100x100, your matrix is too small.

Posted: Fri Oct 03, 2003 10:53 am
by Eva
Sorry for my late reply :(

Actually it was Compile Error,
and I am not sure why :(

Posted: Sat Oct 04, 2003 10:57 am
by Subeen
If you use the function memset() you have to include <string.h> header file.

Posted: Sat Oct 04, 2003 6:43 pm
by Eva
Subeen wrote:If you use the function memset() you have to include <string.h> header file.
Thank you Subeen, but in my compiler (Borland Cpp) it's ok.
Are you talking about gcc ?

Posted: Sun Oct 05, 2003 5:06 am
by Subeen
Yes, I am talking about gcc. ( and I also use BC++ :))

Why WA?

Posted: Thu Oct 09, 2003 7:26 pm
by sumankar

Code: Select all

[c]
#include<stdio.h>

int main()
{
	int n,m,c,i,j,ncase=0;
	char brd[100][100];

	while( scanf("%d %d",&n,&m) == 2 ) {
		ncase++;
		if( n == 0 && m == 0 )
			exit(0);
		for( i = 0 ; i < n ; i++ )
			for( j = 0 ; j < m ;  )
				if( (c = getchar()) != '\n' ) 
					if( c == '*' || c == '.' )
						brd[i][j++] = c=='.'?'0':c;

		for( i = 0 ; i < n ; i++ ) {
			for( j = 0 ; j < m ; j++ )
				if( brd[i][j] == '*' ){					
					if( i < n-1 && j > 0 && brd[i+1][j-1] != '*' ) brd[i+1][j-1]++;
					if( i < n-1 && j < n-1 && brd[i+1][j+1] != '*' ) brd[i+1][j+1]++;
					if( i < n-1 && brd[i+1][j] != '*' ) brd[i+1][j]++;
					if( i > 0 && brd[i-1][j] != '*' ) brd[i-1][j]++;
					if( i > 0 && j > 0 && brd[i-1][j-1] != '*' ) brd[i-1][j-1]++;
					if( i > 0 && j < n-1 && brd[i-1][j+1] != '*' )brd[i-1][j+1]++;
					if( j < n-1 && brd[i][j+1] != '*' ) brd[i][j+1]++;
					if( j > 0 && brd[i][j-1] != '*' ) brd[i][j-1]++;
				}
		}
		printf("Field #%d:\n",ncase);
		for( i = 0 ; i < n ; i++ ) {
			for( j = 0 ; j < m ; j++ )
				printf("%c",brd[i][j]);
			printf("\n");
		}
		printf("\n");
	}
	return 0;
}
[/c]
Any help is appreciated .
Suman.

Posted: Sun Nov 16, 2003 3:36 pm
by r.z.
I still don't know why is my code resulting WA

the sampe input and output is correct, maybe I missed something?

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

void main()
{
int n,m;
int i,j;
int k,l;
int ctr;
int num;
char mat[100][100];

num=1;

/*
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
*/

do
{

memset(mat,'0',sizeof(mat));
scanf("%d %d\n",&n,&m);
if(n==0 && m==0)
break;


for(i=0;i<n;i++)
{
gets(mat);
}

for(i=0;i<n;i++)
{
for(j=0;j<m;j++)
{
ctr=0;
if(mat[j]!='*')
{
for(k=i-1;k<=i+1;k++)
{
for(l=j-1;l<=j+1;l++)
{
if(mat[k][l]=='*')
ctr++;
}
}
mat[j]=ctr+'0';
}
}
}

printf("Field #%d:\n",num);
for(i=0;i<n;i++)
{
for(j=0;j<m;j++)
{
printf("%c",mat[j]);
}
printf("\n");
}
num++;
printf("\n");

}while(n!=0 && m!=0);

/*
fcloseall();
*/

}

[/c]

Posted: Sun Nov 16, 2003 9:29 pm
by Hisoka
maybe like this :

1. array [100][101] => because of string => "aaaa\0" => NULL character
2. when i || j == 0 => k=-1 || l=-1.
3. when i || j == 100 => k=101 || l=101.

I just found this...

Posted: Mon Nov 17, 2003 1:46 am
by r.z.
thanks got accepted
I forgot about '\0'

10189 Comile errer?

Posted: Wed Dec 03, 2003 10:44 am
by mooseelkdog
I keep getting a compile error, but I can compile and run my program with no error, can anyone explain why (I use g++)?

Thank you,

med
PS - I can send the code if anyone wants me to