※ 글쓴이는 취미로 코딩을 익혀보는 사람이라 정확하지 않은 내용을 담고 있을 수 있다 ※

 

이번에 볼 문제는 백준 26392번 문제인 Desni klik이다.
문제는 아래 링크를 확인하자.

https://www.acmicpc.net/problem/26392 

 

26392번: Desni klik

The first line contains integers n, r and s (1 ≤ n ≤ 20, 2 ≤ r, s ≤ 50), the number of NFPs, and the number of rows and colums of the matrices. n matrices follows, one below another, each with r rows and s columns, representing NFP values. Each col

www.acmicpc.net

각 테스트케이스마다 '#'이 포함되어있는 가장 높은 행과 낮은 행을 찾아 그 차를 출력해주는 것으로 문제를 해결할 수 있다.

 

이는 반복문을 이용하여 간단히 찾아낼 수 있다.

 

아래는 제출한 소스코드이다.

#include <iostream>
#include <string>
using namespace std;

int T;
int R, C;
string board[50];

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);

	cin >> T >> R >> C;
	while (T--) {
		for (int r = 0; r < R; r++) cin >> board[r];
		int rmn = 0, rmx = R - 1;
		for (; rmn < R; rmn++) {
			bool chk = 0;
			for (int c = 0; c < C; c++) {
				if (board[rmn][c] == '#') chk = 1;
			}
			if (chk) break;
		}
		for (; rmx > -1; rmx--) {
			bool chk = 0;
			for (int c = 0; c < C; c++) {
				if (board[rmx][c] == '#') chk = 1;
			}
			if (chk) break;
		}

		cout << rmx - rmn << '\n';
	}
}
728x90

+ Recent posts