-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCountFills39a.java
More file actions
106 lines (104 loc) · 2.63 KB
/
Copy pathCountFills39a.java
File metadata and controls
106 lines (104 loc) · 2.63 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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
import java.util.Scanner;
public class CountFills39a{
public static void main(String args[]) {
Scanner sc=new Scanner(System.in);
final int SIZE = 8;
int c[][] = { { 1, 0, 1, 0, 1, 0, 1, 1 }, { 0, 1, 0, 0, 0, 0, 0, 1 }, { 0, 0, 1, 1, 1, 1, 0, 1 },
{ 0, 0, 1, 0, 1, 1, 1, 1 }, { 0, 1, 1, 0, 1, 1, 1, 1 }, { 0, 0, 0, 0, 0, 0, 0, 1 }, { 0, 0, 0, 0, 0, 0, 1, 1 },
{ 0, 0, 0, 0, 0, 0, 0, 0 } };
int xCount[][] = new int[SIZE][SIZE + 1];
int yCount[][] = new int[SIZE + 1][SIZE];
int xmx[] = new int[SIZE];
int xw=0;
int yw=0;
int ymx[] = new int[SIZE];
int x = 0, y = 0;
int cnt = 0;
for (y = 0; y < SIZE; y++) {
cnt = 0;
for (x = 0; x < SIZE; x++) {
if(c[y][x]==1){
while(x<SIZE&&c[y][x]==1){
xCount[y][cnt]++;
x++;
}
cnt++;
}
}
xmx[y] = cnt;
xw=Math.max(xw,cnt);
}
cnt = 0;
for (y = 0; y < SIZE; y++) {
cnt = 0;
for (x = 0; x < SIZE; x++) {
if(c[x][y]==1){
while(x<SIZE&&c[x][y]==1){
yCount[cnt][y]++;
x++;
}
cnt++;
}
}
ymx[y] = cnt;
yw=Math.max(yw,cnt);
}
for(int i=0;i<yw;i++){
for(int j=0;j<xw*2+1;j++){
System.out.print(" ");
}
for(int j=0;j<SIZE;j++){
if(ymx[j]>=yw-i){
System.out.print(yCount[ymx[j]-yw+i][j]+" ");
}else{
System.out.print(" ");
}
}
System.out.print("\n");
}
for(int j=0;j<xw*2+1;j++){
System.out.print(" ");
}
System.out.println("---------------");
for(int i=0;i<SIZE;i++){
for(int j=0;j<xw;j++){
if(j==xw-1){
if(xmx[i]>=xw-j){
System.out.print(xCount[i][xmx[i]-xw+j]);
}else{
System.out.print(" ");
}
break;
}
if(xmx[i]>=xw-j){
System.out.print(xCount[i][xmx[i]-xw+j]+" ");
}else{
System.out.print(" ");
}
}
System.out.print("||");
for(int j=0;j<SIZE;j++){
System.out.print("_"+" ");
}
System.out.print("\n");
}
System.out.println("Q:Write 0 or 1 in this blank(_)");
int ans[][]=new int[SIZE][SIZE];
for(int i=0;i<SIZE;i++){
for(int j=0;j<SIZE;j++){
ans[i][j]=sc.nextInt();
}
}
int jadge=1;
for(int i=0;i<SIZE;i++){
for(int j=0;j<SIZE;j++){
if(c[i][j]!=ans[i][j]) jadge=0;
}
}
if(jadge==1){
System.out.println("Clear!! You are very cool!!!");
}else{
System.out.println("Wrong answer! Please try again...");
}
}
}