๋ฌธ์ (์ถ์ฒ: https://www.acmicpc.net/problem/2799)
< ๋ธ๋ผ์ธ๋ >
๋ฌธ์ ํ์ด
4x4 ๊ตฌ๊ฐ์ ํ์ํด์ ์ฐฝ๋ฌธ์ ์ข ๋ฅ๋ฅผ ํ์ธํ๋ค.
my solution (Java)
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 _2799_ { // ๋ธ๋ผ์ธ๋
public static void main(String[] args) throws IOException {
BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
StringTokenizer st = new StringTokenizer(bf.readLine());
int m = Integer.parseInt(st.nextToken());
int n = Integer.parseInt(st.nextToken());
int arr[][] = new int[5 * m + 1][5 * n + 1];
int result[] = new int[5];
for (int i = 0; i < 5 * m + 1; i++) {
String str = bf.readLine();
for (int j = 0; j < 5 * n + 1; j++) {
arr[i][j] = str.charAt(j);
}
}
for (int j = 0; j < 5 * n; j += 5) {
for (int i = 0; i < 5 * m; i += 5) {
int cnt = 0;
for (int k = i + 1; k < i + 6; k++) {
if (arr[k][j + 1] == '*') {
cnt += 1;
}
}
result[cnt] += 1;
}
}
for (int i = 0; i < 5; i++) {
bw.write(result[i] + " ");
}
bw.flush();
}
}
๋ณ์)
m, n : m์ธต n๊ฐ์ ์ฐฝ๋ฌธ
arr : ์ํํธ์ ์ํ
result : ๊ฐ ๋ธ๋ผ์ธ๋ ํ์ ๊ฐ์
cnt : ํ ์ฐฝ๋ฌธ์ ๋ธ๋ผ์ธ๋ ํ์
๊ฑด๋ฌผ์ ์ธต ์์ ์ฐฝ๋ฌธ์ ๊ฐ์๋ฅผ ์ ๋ ฅ๋ฐ๋๋ค.
์ํํธ์ ์ ๋ณด๋ฅผ ์ ๋ ฅ๋ฐ์ arr ๋ฐฐ์ด์ ์ ์ฅํ๋ค.
๊ฐ ์ธต๋ง๋ค 4x4 ์ฐฝ๋ฌธ์ ํ์ํ๋ฉฐ ๋ธ๋ผ์ธ๋์ ์ํ๋ฅผ ํ์ธํด์ result ๋ฐฐ์ด์ ์ ์ฅ ํ ์ต์ข ๊ฒฐ๊ณผ๋ฅผ ์ถ๋ ฅํ๋ค.
'๐Algorithm > ๐ฅBaekjoon' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[Baekjoon] 10431_์ค์ธ์ฐ๊ธฐ (1) | 2024.01.29 |
---|---|
[Baekjoon] 2865_๋๋ ์๋ํ ์ํผ์คํK (0) | 2024.01.26 |
[Baekjoon] 10384_ํฌ๊ทธ๋จ (0) | 2024.01.15 |
[Baekjoon] 1865_์ํ (0) | 2024.01.12 |
[Baekjoon] 9694_๋ฌด์์ ์๋๋๊ฐ ์๋๋ผ ๋๊ตฌ๋ฅผ ์๋๋๊ฐ ๋ฌธ์ ๋ค (1) | 2024.01.11 |