Notice
Recent Posts
Recent Comments
Link
| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 1 | 2 | 3 | 4 | 5 | 6 | |
| 7 | 8 | 9 | 10 | 11 | 12 | 13 |
| 14 | 15 | 16 | 17 | 18 | 19 | 20 |
| 21 | 22 | 23 | 24 | 25 | 26 | 27 |
| 28 | 29 | 30 | 31 |
Tags
- 백준 1316
- 백준 2292
- 백준 2566
- 백준 1547
- 2941
- 백준 11653
- 백준 1978
- 백준 1929
- 백준 1264
- 백준 1193
- 백준 2581
- 백준 - 1371
- 백준 10757
- 백준 2563
- 백준 1712
- 백준 2587
- 백준 2750
- 백준 2839
- 프로그래머스
- 백준2869
- 백준 10250
- 자바
- 1157
- Java
- C
- 백준 2738
- 백준 9020
- 백준 2775
- 백준
- 수박수박수박수박수박수?
Archives
- Today
- Total
perry05
[백준] 2941 - 크로아티아 알파벳(JAVA) 본문
[백준] 단계별로 풀어보기 - 문자열
https://www.acmicpc.net/problem/2941
2941번: 크로아티아 알파벳
예전에는 운영체제에서 크로아티아 알파벳을 입력할 수가 없었다. 따라서, 다음과 같이 크로아티아 알파벳을 변경해서 입력했다. 크로아티아 알파벳 변경 č c= ć c- dž dz= đ d- lj lj nj nj š s= ž z=
www.acmicpc.net
> 문제


> 풀이
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String[] alphabet = {"c=", "c-", "dz=", "d-", "lj", "nj", "s=", "z="};
String in;
int cnt = 0;
int remainWords;
in = br.readLine();
remainWords = in.length();
br.close();
for(int i = 0; i < alphabet.length; i++) {
int index = in.indexOf(alphabet[i]);
int l = alphabet[i].length();
while(index != -1) {
if(index!=0 && i ==7 && in.charAt(index-1)=='d') { //i==7 -> "z="
index = in.indexOf(alphabet[i],index+l);
}
else {
index = in.indexOf(alphabet[i],index+l);
cnt++;
remainWords = remainWords - l;
}
}
}
cnt = cnt + remainWords;
System.out.println(cnt);
}
}
dz=과 z=을 처리하는 부분이 조금 더러운 것 같아서 제출 후 다른사람 풀이를 봤는데 replace를 활용하면 더 쉽고 간단하다는 것을 알았다.
'문제풀이 기록 > JAVA' 카테고리의 다른 글
| [백준] 1712 - 손익분기점(JAVA) (0) | 2022.11.28 |
|---|---|
| [백준] 1316 - 그룹 단어 체커(JAVA) (0) | 2022.11.28 |
| [백준] 5622 - 다이얼(JAVA) (0) | 2022.11.28 |
| [백준] 2908 - 상수(JAVA) (0) | 2022.11.28 |
| [백준] 1152 - 단어의 개수(JAVA) (0) | 2022.11.28 |
Comments