728x90
https://swexpertacademy.com/main/solvingProblem/solvingProblem.do
SW Expert Academy
SW 프로그래밍 역량 강화에 도움이 되는 다양한 학습 컨텐츠를 확인하세요!
swexpertacademy.com

import java.util.Scanner;
class Solution {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
for (int tc = 1; tc <= 10; tc++) {
int n = sc.nextInt();
int arr[][] = new int[100][100];
for (int i = 0; i < 100; i++) {
for (int j = 0; j < 100; j++) {
arr[i][j] = sc.nextInt();
}
}
boolean isRed = false;
int count = 0;
for (int i = 0; i < 100; i++) {
for (int j = 0; j < 100; j++) {
if (arr[j][i] == 1) { //빨간색(N극)이 나오는 지점 찾기
isRed = true;
}
if (arr[j][i] == 2 && isRed == true) {//빨간색이 나온 상태에서 파란색이 나오면
count++;// 개수 늘리기
isRed = false; //초기화
}
}
isRed=false;//열 바꿀 때 false로 바꿔야함
}
System.out.println("#" + tc + " " + count);
}
}
}728x90
'SW Expert Academy > SWEA D3' 카테고리의 다른 글
| [SW Expert Academy] [S/W 문제해결 기본] 3일차 - String (D3) (0) | 2024.09.02 |
|---|---|
| [SW Expert Academy] 직사각형 길이 찾기 (D3) (0) | 2024.09.01 |
| [SW Expert Academy] [S/W 문제해결 기본] 7일차 - 암호생성기 (D3) (1) | 2024.09.01 |
| [SW Expert Academy] 보충학습과 평균 (D3) (0) | 2024.08.31 |
| [SW Expert Academy] 원 안의 점 (D3) (0) | 2024.08.31 |