```
백준 8371, 8387번 Dyslexia JAVA 구현해보기
```
이번 글을 통해 배워갈 내용
- 백준 8371번 풀이
- 백준 8387번 풀이
https://www.acmicpc.net/problem/8371
8371번: Dyslexia
In the recent years children in Byteland have been hardly reading any books. This has a negative influence on the knowledge of orthography among Byteland residents. Teachers at schools do their best to change this situation. They organize many different te
www.acmicpc.net
https://www.acmicpc.net/problem/8387
8387번: Dyslexia
In the recent years children in Byteland have been hardly reading any books. This has a negative influence on the knowledge of orthography among Byteland residents. Teachers at schools do their best to change this situation. They organize many different te
www.acmicpc.net
8371은
2개의 문자열을 입력받고 틀린 문자의 개수를 세고
8387은
2개의 문자열을 입력받고 같은 문자의 개수를 세면됩니다.
30분 정도 위에 링크를 방문하셔서 풀어보시고
안 풀리시는 경우에만 아래 해답을 봐주시면 감사하겠습니다.
아래의 비교하는 부분만 바꿔주시면 됩니다.
같은 문자의 경우 == 로 확인
틀린 문자의 경우!= 로 확인하여 풀었습니다.
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class Main {
static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
public static void main(String[] args) throws IOException {
System.out.print(findCorrectlyRewrittenLetters());
}
private static int findCorrectlyRewrittenLetters() throws IOException {
int retCnt = 0;
int len = Integer.parseInt(br.readLine());
String str1 = br.readLine();
String str2 = br.readLine();
for (int i = 0; i < len; i++) {
if (str1.charAt(i) == str2.charAt(i)) {
retCnt++;
}
}
return retCnt;
}
}
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class Main {
static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
public static void main(String[] args) throws IOException {
System.out.print(findIncorrectlyRewrittenLetters());
}
private static int findIncorrectlyRewrittenLetters() throws IOException {
int retCnt = 0;
int len = Integer.parseInt(br.readLine());
String str1 = br.readLine();
String str2 = br.readLine();
for (int i = 0; i < len; i++) {
if (str1.charAt(i) != str2.charAt(i)) {
retCnt++;
}
}
return retCnt;
}
}
읽어주셔서 감사합니다
무엇인가 얻어가셨기를 바라며
오늘도 즐거운 코딩 하시길 바랍니다 ~ :)
'Java > Java 알고리즘' 카테고리의 다른 글
백준 4153번 직각삼각형 JAVA 구현해보기 (0) | 2022.02.05 |
---|---|
백준 16120번 PPAP JAVA 구현해보기 (0) | 2022.02.05 |
백준 10101번 삼각형 외우기 JAVA 구현해보기 (0) | 2022.02.05 |
백준 10156번 과자 JAVA 구현해보기 (0) | 2022.02.05 |
백준 9184번 신나는 함수 실행 수열JAVA 구현해보기 (0) | 2022.02.04 |