

알고리즘
1. 입력받은 값에 앞뒤로 공백이 있을 수 있으니 문자열 공백제거를 위해 trim()을 사용한다.
String input = br.readLine().trim();
2. 입력받은 input에 cro_apl 배열에 속한 값이 있다면 해당된 문자열은 *으로 바꿔준다.
이 작업을 하지 않을 경우 에러발생
for(int i=0; i<cro_alp.length; i++) {
if(input.contains(cro_alp[i])) {
input = input.replaceAll(cro_alp[i], "*");
}
}
최종코드
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));
String [] cro_alp = {"c=", "c-", "dz=", "d-","lj","nj","s=","z="};
String input = br.readLine().trim(); //앞뒤 공백 제거(trim)
for(int i=0; i<cro_alp.length; i++) {
if(input.contains(cro_alp[i])) {
input = input.replaceAll(cro_alp[i], "*"); //속한 문자열 모두 *로 바뀐다
}
}
bw.write(input.length()+"");
bw.flush();
bw.close();
br.close();
}
}
'Study > [Algorithm]' 카테고리의 다른 글
[백준] 10250번 - ACM 호텔 (0) | 2021.06.10 |
---|---|
[백준] 1316번 - 그룹 단어 체커 (0) | 2021.05.30 |
[백준] 1929번 - 소수 구하기 (0) | 2021.05.28 |
[백준] 1152번 JAVA - 단어의 개수 (0) | 2021.05.27 |
[백준] 2577번 JAVA - 숫자의 개수 (0) | 2021.05.21 |
댓글