https://www.acmicpc.net/problem/1236
1236๋ฒ: ์ฑ ์งํค๊ธฐ
์ฒซ์งธ ์ค์ ์ฑ์ ์ธ๋ก ํฌ๊ธฐ N๊ณผ ๊ฐ๋ก ํฌ๊ธฐ M์ด ์ฃผ์ด์ง๋ค. N๊ณผ M์ 50๋ณด๋ค ์๊ฑฐ๋ ๊ฐ์ ์์ฐ์์ด๋ค. ๋์งธ ์ค๋ถํฐ N๊ฐ์ ์ค์๋ ์ฑ์ ์ํ๊ฐ ์ฃผ์ด์ง๋ค. ์ฑ์ ์ํ๋ .์ ๋น์นธ, X๋ ๊ฒฝ๋น์์ด ์๋ ์นธ์ด๋ค
www.acmicpc.net
์ค๋ต๋ ธํธ(ํธ๋ ๋์ ์ฌ๊ณ ๊ณผ์ ๋ฐ ๊ฐ์ ์ )
์ด๋ฒ์๋ ๋คํํ ๋ง์ถ ์ ์์๋ค.
์ ๋ ฅ์ด ๋์๋ฆฌ์๋ฉด charAt์ผ๋ก ๋์๊ฒฝ์ฐ ์์๋ชปํ ๋์์ด ์ด๋ฃจ์ด์ ธ NegativeArraySize๋ฅผ ์ผ๊ธฐํ๋๋ฐ, split์ผ๋ก ์ฒ๋ฆฌํ๋ ์์ฃผ ์ ๋์๊ฐ๋ค.
์ ๋ต์ฝ๋
import java.io.*;
class Main{
public static void main(String[] args) throws IOException{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String[] size = br.readLine().split(" ");
int N = Integer.parseInt(size[0]);
int M = Integer.parseInt(size[1]);
int[] nmap = new int[N];
int[] mmap = new int[M];
int nRes = N;
int mRes = M;
for(int i=0; i<N; i++){
boolean isRowExist = false;
String tmp = br.readLine();
for(int j=0; j<M; j++){
if(tmp != null && tmp.charAt(j) == 'X'){
if(mmap[j] == 0){
mmap[j] = 1;
mRes--;
}
isRowExist = true;
}
}
if(isRowExist == true && nmap[i]==0){
nmap[i] = 1;
nRes--;
}
}
//counting
int res = Math.max(mRes, nRes);
System.out.println(res);
br.close();
}
}
์ด์ฐจํผ ํ/์ด์์ ์ญ์๊ฐ ๋ชจ์์ผ๋ก ์ฒดํฌํ๋ฉด๋๋ค. ์ฆ ๊ฒน์น๋ ๊ฒ์ ๋ ํฐ ๊ฒ์ ํก์๋๋ค๊ณ ์ดํดํ๋ฉด ๋๋ค.
์ฒ์์ Math.max๋ฅผ ์ฐ๊ธฐ ์ ์๋ ? : ์ผํญ์ฐ์ฐ์๋ฅผ ์ฌ์ฉํ๋ ค๊ณ ํ๋ค.
abs, max, min์ ์ ์ ํ ์ฌ์ฉํ๋ ์ต๊ด์ ๋ค์ฌ์ผ๊ฒ ๋ค..
"๋๊ธ, ๊ณต๊ฐ ๋ฒํผ ํ ๋ฒ์ฉ ๋๋ฅด๊ณ ๊ฐ์ฃผ์๋ฉด ํฐ ํ์ด ๋ฉ๋๋ค"
'OJ๐ผ > ์ค๋ต๋ ธํธ๐' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[BOJ][JAVA] 10989: ์ ์ ๋ ฌํ๊ธฐ 3 (0) | 2023.10.19 |
---|---|
[BOJ][JAVA] 3273: ๋ ์์ ํฉ (0) | 2023.10.16 |
[BOJ][JAVA] 10158: ๊ฐ๋ฏธ (0) | 2023.10.08 |
[BOJ][JAVA] 13223: ์๊ธํญํ (0) | 2023.10.05 |
[BOJ][JAVA] 1543: ๋ฌธ์ ๊ฒ์ (0) | 2023.10.03 |