728x90
반응형
풀이 :
문제 이해 후 (1,2) 순서인 것만 카운팅해주면 되는 규칙을 잘 찾아야함. for문과 if문, boolean check 를 사용해서 풀이
Code
public class Solution1220 {
public static void main(String[] args) throws IOException {
Scanner sc = new Scanner(System.in);
for (int tc = 1; tc <= 10; tc++) {
int N = sc.nextInt(); // 100
int[][] map = new int[N][N]; // 100 X 100 배열
int result = 0;
// 입력 받기 -> 1: 빨(N) 2: 파(S)
for (int i = 0; i < map.length; i++) {
for (int j = 0; j < map.length; j++) {
map[i][j] = sc.nextInt();
}
}
for (int i = 0; i < map.length; i++) {
boolean check = false;
for (int j = 0; j < map.length; j++) {
if (map[j][i] == 1) {
check = true;
} else if (map[j][i] == 2) {
if (check) {
result++;
check = false;
}
}
}
}
System.out.println("#" + tc + " " + result);
}
}
}
728x90
반응형
'SWEA' 카테고리의 다른 글
swea 1225 [D3] [S/W 문제해결 기본] 7일차 - 암호생성기 JAVA (1) | 2023.11.24 |
---|---|
swea 1221 [D3] [S/W 문제해결 기본] 5일차 - GNS JAVA (1) | 2023.11.24 |
swea 1217 [D3] [S/W 문제해결 기본] 4일차 - 거듭 제곱 JAVA (0) | 2023.11.24 |
swea 1216 [D3] [S/W 문제해결 기본] 3일차 - 회문2 JAVA (0) | 2023.11.24 |
swea 1215 [D3] [S/W 문제해결 기본] 3일차 - 회문1 JAVA (0) | 2023.11.24 |