-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcodejam1(java).java
More file actions
62 lines (61 loc) · 1.09 KB
/
codejam1(java).java
File metadata and controls
62 lines (61 loc) · 1.09 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
import java.util.*;
public class cj1
{
public static void main(String args[])
{
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
int cou = 0;
while(t-- > 0)
{
int trace=0;
int row=0;
int col=0;
int n = sc.nextInt();
int a[][] = new int[n][n];
for(int i=0;i<n;i++)
{
for(int j=0;j<n;j++)
{
a[i][j] = sc.nextInt();
}
}
for(int i=0;i<n;i++)
{
for(int j=0;j<n;j++)
{
if (i == j)
trace += a[i][j];
}
}
for(int i=0;i<n;i++)
{
int temp=0;
HashMap<Integer,Integer> hs = new HashMap<>();
for(int j=0;j<n;j++)
{
hs.put(a[i][j],1);
if(hs.size() == n)
temp=1;
}
if(temp != 1)
row++;
}
for(int i=0;i<n;i++)
{
int temp=0;
HashMap<Integer,Integer> hs = new HashMap<>();
for(int j=0;j<n;j++)
{
hs.put(a[j][i],1);
if(hs.size() == n)
temp=1;
}
if(temp != 1)
col++;
}
System.out.println("Case #" + (cou+1) + ": " + trace + " " + row + " " + col);
cou++;
}
}
}