Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 4dac109

Browse files
committed
Coding question added
1 parent 72fd0c0 commit 4dac109

File tree

1 file changed

+60
-0
lines changed

1 file changed

+60
-0
lines changed
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
public class CodingQuestion17_11 {
2+
public static boolean isValid(int a, int b, int n) {
3+
return 0<=a && a<n && 0<= b && b<n;
4+
}
5+
6+
static int max = -1;
7+
static int arr[][] = {
8+
{0, 1, 0, 1, 0, 0, 0},
9+
{0, 0, 0, 1, 0, 0, 1},
10+
{0, 1, 0, 0, 0, 0, 1},
11+
{0, 0, 0, 0, 1, 0, 1},
12+
{0, 1, 0, 1, 0, 0, 0},
13+
{0, 0, 1, 1, 0, 0, 1},
14+
{0, 1, 1, 1, 0, 0, 1}
15+
};
16+
17+
public static void dot1() {
18+
for (int i = 0; i < arr.length; i++) {
19+
for (int j = 0; j < arr.length; j++) {
20+
if (arr[i][j] == 1) {
21+
dot2(new Point(i, j));
22+
}
23+
}
24+
}
25+
}
26+
27+
public static void dot2(Point dot1) {
28+
for (int i = dot1.c+1; i <arr.length; i++) {
29+
if (arr[dot1.r][i] == 1)
30+
check(dot1, new Point(dot1.r, i));
31+
}
32+
}
33+
34+
public static void check(Point dot1, Point dot2) {
35+
int diff = dot2.c - dot1.c;
36+
if (isValid(dot1.r + diff, dot2.r + diff, arr.length)
37+
&& arr[dot1.r + diff][dot1.c] == 1 && arr[dot2.r + diff][dot2.c] == 1) {
38+
int square = (int)Math.pow(diff+1, 2);
39+
if (max < square)
40+
max = square;
41+
}
42+
}
43+
44+
public static void main(String[] args) {
45+
dot1();
46+
System.out.println(max);
47+
}
48+
49+
static class Point {
50+
private int r;
51+
private int c;
52+
53+
public Point(int r, int c) {
54+
this.r = r;
55+
this.c = c;
56+
}
57+
}
58+
}
59+
60+

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /