SWEA_1979) 어디에 단어가 들어갈 수 있을까
SWEA
# D2
1979) 어디에 단어가 들어갈 수 있을까 (19.10.04)
문제 링크 (SW Expert Academy)
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
|
import java.util.*;
import java.io.*;
public class Solution {
public static void main(String args[]) throws IOException{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
StringTokenizer tk;
int t = Integer.parseInt(br.readLine());
for(int i=1;i<=t;i++) {
tk = new StringTokenizer(br.readLine());
int n = Integer.parseInt(tk.nextToken());
int k = Integer.parseInt(tk.nextToken());
int[][] map = new int[n][n];
for(int p=0;p<n;p++) {
tk = new StringTokenizer(br.readLine());
for(int q=0;q<n;q++) {
map[p][q] = Integer.parseInt(tk.nextToken());
}
}
int ans = 0;
int cnt = 0;
for(int p=0;p<n;p++) {
for(int q=0;q<n;q++) {
if(map[p][q]==1) cnt = cnt+1;
if(q==n-1 || map[p][q]==0){
if(cnt==k) ans = ans+1;
cnt = 0;
}
}
}
int ans2 = 0;
int cnt2 = 0;
for(int p=0;p<n;p++) {
for(int q=0;q<n;q++) {
if(map[q][p]==1) cnt2 = cnt2+1;
if(q==n-1 || map[q][p]==0){
if(cnt2==k) ans2= ans2+1;
cnt2 = 0;
}
}
}
bw.write("#" + i + " " + (ans+ans2) + "\n");
}
bw.flush();
bw.close();
}
}
| cs |
댓글
댓글 쓰기