-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSWEA1979.java
More file actions
84 lines (69 loc) · 1.49 KB
/
SWEA1979.java
File metadata and controls
84 lines (69 loc) · 1.49 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
package com.study.code.solved;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
public class SWEA1979 {
private static Scanner sc;
public static void main(String[] args) {
sc = new Scanner(System.in);
int tcN = sc.nextInt();
for (int tc = 1; tc <= tcN; tc++) {
int N = sc.nextInt();
int K = sc.nextInt();
int[][] arr = new int[N][N];
for(int i = 0; i < N; i++) {
for(int j =0; j < N; j++) {
arr[i][j] = sc.nextInt();
}
}
// for(int i = 0; i < N; i++) {
// for(int j =0; j < N; j++) {
// System.out.print(arr[i][j] + " ");
// }
// System.out.println();
// }
List<Integer> ns = new ArrayList<Integer>();
int sum = 0;
//°¡·Î
for(int i = 0; i < N; i++) {
sum = 0;
for(int j =0; j < N; j++) {
if(arr[i][j] == 0) {
ns.add(sum);
sum = 0;
}else if(j == N-1) {
sum += arr[i][j];
ns.add(sum);
}else {
sum += arr[i][j];
}
}
}
//System.out.println(ns.toString());
//¼¼·Î
for(int i = 0; i < N; i++) {
sum = 0;
for(int j =0; j < N; j++) {
if(arr[j][i] == 0) {
ns.add(sum);
sum = 0;
}else if(j == N-1) {
sum += arr[j][i];
ns.add(sum);
}else {
sum += arr[j][i];
}
}
}
//System.out.println(ns.toString());
int ans = 0;
for(int i =0; i < ns.size();i++) {
if(ns.get(i) == K) {
ans++;
}
}
System.out.println("#" + tc + " " + ans);
}
sc.close();
}
}