forked from jaspreetkaur96/CodingQuestions
- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBoolean Matrix.java
More file actions
Latest commit
79 lines (66 loc) · 1.94 KB
/
Copy pathBoolean Matrix.java
File metadata and controls
79 lines (66 loc) · 1.94 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
/*package whatever //do not write package name here */
importjava.util.*;
importjava.lang.*;
importjava.io.*;
classGFG {
publicstaticvoidmain (String[] args) throwsIOException {
BufferedReaderbr = newBufferedReader(newInputStreamReader(System.in));
inttests = Integer.parseInt(br.readLine());
for(intt = 0 ; t < tests ; t++)
{
Stringorder [] = br.readLine().split(" ");
introws = Integer.parseInt(order[0]);
intcols = Integer.parseInt(order[1]);
booleanrow_array[] = newboolean[rows];
booleancol_array[] = newboolean[cols];
booleana [][] = newboolean[rows][cols];
for(inti = 0 ; i < rows ; i++)
{
Stringsplit_row [] = br.readLine().split(" ");
for(intj = 0 ; j < cols ; j++)
{
a[i][j] = Integer.parseInt(split_row[j]) > 0 ? true : false;
// a[i][j] = i > 0 ? true : falsesc.nextBoolean();
if(a[i][j] == true)
{
row_array[i] = true;
col_array[j] = true;
}
}
}
for(intj = 0 ; j < cols ;j++) //row 0
{
if(col_array[j] == true)
{
for(inti = 0 ; i < rows; i++)
{
a[i][j] = true;
}
}
}
for(intj = 0 ; j < rows ;j++) //col 1
{
if(row_array[j] == true)
{
for(inti = 0 ; i < cols; i++)
{
a[j][i] = true;
}
}
}
StringBuildersb = newStringBuilder();
for(inti = 0 ; i < rows ; i++)
{
for(intj = 0 ; j < cols ; j++)
{
if(a[i][j] == true)
sb.append(1 +" ");
elsesb.append(0 +" ");
}
sb.append("\n");
}
sb.setLength(sb.length() - 1);
System.out.println(sb);
}
}
}