-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathCavityMap.java
More file actions
73 lines (72 loc) · 1.26 KB
/
CavityMap.java
File metadata and controls
73 lines (72 loc) · 1.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import java.io.*;
import java.lang.*;
import java.util.Scanner;
class CavityMap
{
public static void main(String[]args)throws IOException
{
BufferedReader venki=new BufferedReader(new InputStreamReader(System.in));
int n=Integer.parseInt(venki.readLine());
String grid[]=new String[n];
int i,j,x=0,a[][]=new int[n][n];
int row=0,col=0;
int l,m,k,o,p,q,r,t;
for(i=0;i<n;i++)
{
grid[i]=venki.readLine();
}
if(n<3)
{
for(i=0;i<n;i++)
{
System.out.println(grid[i]);
}
}
else
{
for(i=0;i<n;i++)
{
String s=grid[i];
for(j=0;j<n;j++)
{
char c=s.charAt(j);
a[i][j]=Character.getNumericValue(c);
}
}
for(i=1;i<n-1;i++)
{
for(j=1;j<n-1;j++)
{
if((i!=0)&&(j!=0)&&(i!=(n-1))&&(j!=(n-1)))
{
x=a[i][j];
k=a[i][j+1];
o=a[i][j-1];
p=a[i+1][j];
q=a[i-1][j];
System.out.println("\nX :"+x+"\nK :"+k+"\nO :"+o+"\nP :"+p+"\nQ :"+q+"\n");
if(x>k)
{
if(x>o)
{
if(x>p)
{
if(x>q)
{
a[i][j]=11;
char ch=grid[i].charAt(j);
grid[i]=grid[i].replace(ch,'X');
}
}
}
}
}
}
}
for(i=0;i<n;i++)
{
System.out.println(grid[i]);
}
}
}
}