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
Snakib
New poster
Posts: 7 Joined: Mon May 31, 2010 6:25 am
Post
by Snakib » Fri May 31, 2013 4:26 pm
What is the wrong with the code . can anybody tell me. it giving the right answer as far as i know
Code: Select all
#define i64 long long
#include<cstdio>
#include<iostream>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<vector>
#include<string>
#include<cstdlib>
using namespace std;
int main()
{
int n,m,i,j,k,l,count = 1;
char a[104][104],b[104][104];
while ( scanf("%d%d",&n,&m) == 2)
{
if( n == 0 && m == 0 )
break;
for( i = 0 ; i < n ; i++ )
for( j = 0 ; j < m ; j++ )
b[i][j] = '0';
getchar();
for( i = 0 ; i < n ; i++ )
{
for( j = 0 ; j < m ; j++ )
{
a[i][j] = getchar();
if( a[i][j] == '*' )
{
b[i][j] = '*';
for( k = i-1 ; k <= i+1 ; k++ )
for( l = j-1 ; l <= j+1 ; l++ )
{
if( k < 0 || l < 0 || k >99 || l > 99 || a[k][l] == '*' )
continue;
else
b[k][l] += 1;
}
}
}
getchar();
}
if( count != 1 )
printf("\n");
printf("Field #%d:\n",count);
for( i = 0 ; i < n ; i++ )
{
for( j = 0 ; j < m ; j++ )
printf("%c",b[i][j]);
printf("\n");
}
count++;
}
}
brianfry713
Guru
Posts: 5947 Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA
Post
by brianfry713 » Tue Jun 11, 2013 4:01 am
Check input and AC output for thousands of problems on
uDebug !
Snakib
New poster
Posts: 7 Joined: Mon May 31, 2010 6:25 am
Post
by Snakib » Tue Jun 11, 2013 11:01 pm
brianfry713
Guru
Posts: 5947 Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA
Post
by brianfry713 » Wed Jun 12, 2013 12:18 am
Try input:
Code: Select all
4 4
*...
....
.*..
....
3 5
**...
.....
.*...
1 3
*.*
0 0
Check input and AC output for thousands of problems on
uDebug !
Snakib
New poster
Posts: 7 Joined: Mon May 31, 2010 6:25 am
Post
by Snakib » Wed Jun 12, 2013 1:17 pm
cursor shows like this
Code: Select all
4 4
*...
....
.*..
....
Field #1:
*100
2210
1*10
1110
3 5
**...
.....
.*...
Field #2:
**100
33200
1*100
1 3
*.*
Field #3:
*1*
0 0
Process returned 0 (0x0) execution time : 8.471 s
Press any key to continue.
brianfry713
Guru
Posts: 5947 Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA
Post
by brianfry713 » Thu Jun 13, 2013 12:13 am
Do you see the error in your code?
Check input and AC output for thousands of problems on
uDebug !
??????
New poster
Posts: 6 Joined: Thu Jun 13, 2013 5:40 am
Post
by ?????? » Thu Jun 13, 2013 5:48 am
Why i am getting Wrong Answer? Can anyone help? Here is my code
Code: Select all
#include <stdio.h>
#include <string.h>
int main()
{
char s[1000][1000],ch;
long long int n,m,i,j,x,y,i1,j1,t;
for(t=1;;)
{
scanf("%lld%lld",&n,&m);if(m==0&n==0) {break;}
if(n>0&&m>0&&n<=100&&m<=100)
{
for(i=0;i<n;i++)
{
for(j=0;j<m;)
{
scanf("%c",&ch);if(ch=='*'||ch=='.') { s[i][j]=ch; if(ch=='.') {s[i][j]='0';} j++; }
}
}
for(x=0;x<n;x++)
{
for(y=0;y<m;y++)
{
if(s[x][y]=='*')
{
if(x!=0 && y!=0 && x!=n-1&&y!=m-1)
{
if(s[x-1][y-1]!='*') {s[x-1][y-1]=s[x-1][y-1]+1; }
if(s[x-1][y]!='*') {s[x-1][y]=s[x-1][y]+1;}
if(s[x-1][y+1]!='*') {s[x-1][y+1]=s[x-1][y+1]+1;}
if(s[x][y-1]!='*') {s[x][y-1]=s[x][y-1]+1;}
if(s[x][y+1]!='*') {s[x][y+1]=s[x][y+1]+1;}
if(s[x+1][y-1]!='*') {s[x+1][y-1]=s[x+1][y-1]+1;}
if(s[x+1][y]!='*') {s[x+1][y]=s[x+1][y]+1;}
if(s[x+1][y+1]!='*') {s[x+1][y+1]=s[x+1][y+1]+1;}
}
else if(x==0 && y!=0 && y!=m-1)
{
if(s[x][y-1]!='*') {s[x][y-1]=s[x][y-1]+1; }
if(s[x][y+1]!='*') {s[x][y+1]=s[x][y+1]+1;}
if(s[x+1][y-1]!='*') {s[x+1][y-1]=s[x+1][y-1]+1;}
if(s[x+1][y]!='*') {s[x+1][y]=s[x+1][y]+1; }
if(s[x+1][y+1]!='*') {s[x+1][y+1]=s[x+1][y+1]+1;}
}
else if(x==n-1 && y!=0 && y!=m-1)
{
if(s[x-1][y-1]!='*') {s[x-1][y-1]=s[x-1][y-1]+1;}
if(s[x-1][y]!='*') {s[x-1][y]=s[x-1][y]+1;}
if(s[x-1][y+1]!='*') {s[x-1][y+1]=s[x-1][y+1]+1;}
if(s[x][y-1]!='*') {s[x][y-1]=s[x][y-1]+1; }
if(s[x][y+1]!='*') {s[x][y+1]=s[x][y+1]+1;}
}
else if(y==0 && x!=0&& x!=n-1)
{
if(s[x-1][y]!='*') {s[x-1][y]=s[x-1][y]+1;}
if(s[x-1][y+1]!='*') {s[x-1][y+1]=s[x-1][y+1]+1;}
if(s[x][y+1]!='*') {s[x][y+1]=s[x][y+1]+1;}
if(s[x+1][y]!='*') {s[x+1][y]=s[x+1][y]+1; }
if(s[x+1][y+1]!='*') {s[x+1][y+1]=s[x+1][y+1]+1;}
}
else if(y==m-1 && x!=n-1&&x!=0)
{
if(s[x-1][y-1]!='*') {s[x-1][y-1]=s[x-1][y-1]+1;}
if(s[x-1][y]!='*') {s[x-1][y]=s[x-1][y]+1;}
if(s[x][y-1]!='*') {s[x][y-1]=s[x][y-1]+1;}
if(s[x+1][y-1]!='*') {s[x+1][y-1]=s[x+1][y-1]+1;}
if(s[x+1][y]!='*') {s[x+1][y]=s[x+1][y]+1;}
}
else if(x==0&&y==0)
{
if(s[x][y+1]!='*') {s[x][y+1]=s[x][y+1]+1;}
if(s[x+1][y]!='*') {s[x+1][y]=s[x+1][y]+1;}
if(s[x+1][y+1]!='*') {s[x+1][y+1]=s[x+1][y+1]+1;}
}
else if(x==n-1&&y==0)
{
if(s[x-1][y]!='*') {s[x-1][y]=s[x-1][y]+1;}
if(s[x-1][y+1]!='*') {s[x-1][y+1]=s[x-1][y+1]+1;}
if(s[x][y+1]!='*') {s[x][y+1]=s[x][y+1]+1;}
}
else if(x==0&&y==m-1)
{
if(s[x][y-1]!='*') {s[x][y-1]=s[x][y-1]+1; }
if(s[x+1][y-1]!='*') {s[x+1][y-1]=s[x+1][y-1]+1;}
if(s[x+1][y]!='*') {s[x+1][y]=s[x+1][y]+1;}
}
else if(x==n-1&&y==m-1)
{
if(s[x-1][y-1]!='*') {s[x-1][y-1]=s[x-1][y-1]+1;}
if(s[x-1][y]!='*') {s[x-1][y]=s[x-1][y]+1;}
if(s[x][y-1]!='*') {s[x][y-1]=s[x][y-1]+1; }
}
}
}
}
printf("Field #%lld:\n",t);t++;
for(i1=0;i1<n;i1++)
{
for(j1=0;j1<m;j1++)
{
printf("%c",s[i1][j1]);
}
printf("\n");
}
printf("\n");
}
}
return 0;
}
brianfry713
Guru
Posts: 5947 Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA
Post
by brianfry713 » Thu Jun 13, 2013 11:27 pm
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 !
Ardeshir81
New poster
Posts: 8 Joined: Wed Jun 12, 2013 5:51 pm
Post
by Ardeshir81 » Mon Jun 17, 2013 9:59 pm
Hi friends!
I get WA too.
I tested the code with lots of test cases, I'm ALMOST sure there is nothing wrong with it.
I will appreciate any help and suggestion
Code: Select all
//n and m are more than 0 and less than 101 .
#include <iostream>
using std :: cout ;
using std :: cin ;
using std :: endl ;
int main ()
{
int n , m , TC = 0 ; //n for rows and m for columns and TC for test case .
cin >> n >> m ;
while (n != 0 && m != 0)
{
TC ++ ;
char board [n + 1] [m + 1] ; //ERROR
for (int i = 0 ; i < n ; i ++)
cin >> board [i] ;
for (int i = 0 ; i < n ; i ++)
for (int j = 0 ; j < m ; j ++)
if (board [i] [j] == '.')
board [i] [j] = '0' ;
for (int i = 0 ; i < n ; i ++)
for (int j = 0 ; j < m ; j ++)
if (board [i] [j] == '*')
{
if (i > 0 && j > 0 && board [i - 1] [j - 1] != '*')
board [i - 1] [j - 1] ++ ;
if (j > 0 && board [i] [j - 1] != '*')
board [i] [j - 1] ++ ;
if (i < n && j > 0 && board [i + 1] [j - 1] != '*')
board [i + 1] [j - 1] ++ ;
if (i > 0 && board [i - 1] [j] != '*')
board [i - 1] [j] ++ ;
if (i < n && board [i + 1] [j] != '*')
board [i + 1] [j] ++ ;
if (i > 0 && j < m && board [i - 1] [j + 1] != '*')
board [i - 1] [j + 1] ++ ;
if (j < m && board [i] [j + 1] != '*')
board [i] [j + 1] ++ ;
if (i < n && j < m && board [i + 1] [j + 1] != '*')
board [i + 1] [j + 1] ++ ;
}
cout << "Field #" << TC << ":\n" ;
for (int i = 0 ; i < n ; i ++)
{
for (int j = 0 ; j < m ; j ++)
cout << board [i] [j] ;
cout << endl ;
}
cin >> n >> m ;
}
return 0 ;
}
THNX
brianfry713
Guru
Posts: 5947 Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA
Post
by brianfry713 » Tue Jun 18, 2013 12:52 am
There must be an empty line between field outputs.
Check input and AC output for thousands of problems on
uDebug !
Ardeshir81
New poster
Posts: 8 Joined: Wed Jun 12, 2013 5:51 pm
Post
by Ardeshir81 » Tue Jun 18, 2013 1:26 am
Thanks brian, you always answer me.
I tried putting a "cout << endl" at the end, but it didn't help, it's the modified code :
Code: Select all
//n and m are more than 0 and less than 101 .
#include <iostream>
using std :: cout ;
using std :: cin ;
using std :: endl ;
int main ()
{
int n , m , TC = 0 ; //n for rows and m for columns and TC for test case .
cin >> n >> m ;
while (n != 0 && m != 0)
{
TC ++ ;
char board [n + 1] [m + 1] ; //ERROR
for (int i = 0 ; i < n ; i ++)
cin >> board [i] ;
for (int i = 0 ; i < n ; i ++)
for (int j = 0 ; j < m ; j ++)
if (board [i] [j] == '.')
board [i] [j] = '0' ;
for (int i = 0 ; i < n ; i ++)
for (int j = 0 ; j < m ; j ++)
if (board [i] [j] == '*')
{
if (i > 0 && j > 0 && board [i - 1] [j - 1] != '*')
board [i - 1] [j - 1] ++ ;
if (j > 0 && board [i] [j - 1] != '*')
board [i] [j - 1] ++ ;
if (i < n && j > 0 && board [i + 1] [j - 1] != '*')
board [i + 1] [j - 1] ++ ;
if (i > 0 && board [i - 1] [j] != '*')
board [i - 1] [j] ++ ;
if (i < n && board [i + 1] [j] != '*')
board [i + 1] [j] ++ ;
if (i > 0 && j < m && board [i - 1] [j + 1] != '*')
board [i - 1] [j + 1] ++ ;
if (j < m && board [i] [j + 1] != '*')
board [i] [j + 1] ++ ;
if (i < n && j < m && board [i + 1] [j + 1] != '*')
board [i + 1] [j + 1] ++ ;
}
cout << "Field #" << TC << ":\n" ;
for (int i = 0 ; i < n ; i ++)
{
for (int j = 0 ; j < m ; j ++)
cout << board [i] [j] ;
cout << endl ;
}
cout << endl ;
cin >> n >> m ;
}
return 0 ;
}
catalan
New poster
Posts: 4 Joined: Sun Jun 16, 2013 8:25 pm
Post
by catalan » Tue Jun 18, 2013 11:29 pm
I am getting WA too. I have checked all test cases I can think of. I also checked for bllank lines between test cases. I also removed a blank line at the end. But still getting WA. Please help. I have provided my code below. I appreciate your help and thanks in advance.
Last edited by
catalan on Sat Jun 22, 2013 2:20 am, edited 1 time in total.
brianfry713
Guru
Posts: 5947 Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA
Post
by brianfry713 » Wed Jun 19, 2013 1:30 am
Ardeshir81 wrote: Thanks brian, you always answer me.
I tried putting a "cout << endl" at the end, but it didn't help
There must be an empty line between field outputs. Don't print an extra blank line at the end of the output.
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
Post
by brianfry713 » Wed Jun 19, 2013 1:35 am
catalan, that is AC code.
Check input and AC output for thousands of problems on
uDebug !
catalan
New poster
Posts: 4 Joined: Sun Jun 16, 2013 8:25 pm
Post
by catalan » Wed Jun 19, 2013 6:45 am
I re submitted and got AC. Thank you Brian.