• 문제 링크
https://www.acmicpc.net/problem/10709
• 풀이 코드
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.util.StringTokenizer;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
StringBuilder sb = new StringBuilder();
StringTokenizer st = new StringTokenizer(br.readLine());
int h = Integer.parseInt(st.nextToken()), w = Integer.parseInt(st.nextToken());
int[][] mat = new int[h][w];
for (int i = 0, j = 0; i < h; i++, j = 0)
for (char c : br.readLine().toCharArray()) mat[i][j++] = c == 'c' ? 0 : -1;
for (int i = 0; i < h; i++) {
for (int j = 0, k = -1; j < w; j++) {
if (mat[i][j] == 0) k = j;
else if (k != -1) mat[i][j] = j - k;
}
}
for (int i = 0; i < h; i++, sb.append('\n')) for (int j = 0; j < w; j++) sb.append(mat[i][j]).append(' ');
bw.write(sb.toString());
bw.flush();
}
}
'Problem Solving > Baekjoon' 카테고리의 다른 글
[백준] 7847 Sales Report - Data Structure / Java (0) | 2025.03.16 |
---|---|
[백준] 33540 Helping Out - Data Structure / Java (0) | 2025.03.15 |
[백준] 5523 경기 결과 - Implementation / Java (0) | 2025.03.13 |
[백준] 5613 계산기 프로그램 - Implementation / Java (0) | 2025.03.12 |
[백준] 2774 아름다운 수 - Implementation / Java (0) | 2025.03.11 |
댓글