This repository was archived by the owner on Feb 13, 2024. It is now read-only.
File tree 1 file changed +73
-0
lines changed
1 file changed +73
-0
lines changed Original file line number Diff line number Diff line change
1
+ import java .io .*;
2
+
3
+ // 비슷한 단어
4
+
5
+ public class BOJ2607 {
6
+
7
+ // 1. 기준이 되는 문자열보다 길이가 한 글자 작은 경우
8
+ // 2. 기준이 되는 문자열보다 길이가 한 글자 큰 경우
9
+ // 3. 기준이 되는 문자열과 길이가 같은 경우
10
+
11
+ public static void main (String [] args ) throws IOException {
12
+
13
+ // 입력 받기
14
+ BufferedReader br = new BufferedReader (new InputStreamReader (System .in ));
15
+
16
+ // br.readline은 String 형태로 받으니까 String 형태를 int 형태로 바꾸기 여기서 기준점을 빼줌
17
+ int n = Integer .parseInt (br .readLine ()) - 1 ;
18
+
19
+ // 기준점을 받아오기
20
+ String standard = br .readLine ();
21
+
22
+ // 기준점에 길이
23
+ int len = standard .length ();
24
+
25
+ // 알파벳의 숫자
26
+ int [] alphabet = new int [26 ];
27
+
28
+ // 대문자 알파벳 숫자 저장
29
+ for (int i = 0 ; i < len ; i ++) {
30
+ alphabet [standard .charAt (i ) - 'A' ]++;
31
+ }
32
+
33
+ // 정답을 받을 변수
34
+ int ans = 0 ;
35
+
36
+ // n이 0 이 될떄까찌
37
+ while (n --> 0 ) {
38
+ // alphabet 배열을 복제
39
+ int [] temp = alphabet .clone ();
40
+ // bufferedReader에 String 입력
41
+ String comp = br .readLine ();
42
+
43
+ int cnt = 0 ;
44
+ for (int i = 0 ; i < comp .length (); i ++) {
45
+ if (temp [comp .charAt (i )- 'A' ] > 0 ) {
46
+ cnt ++;
47
+ temp [comp .charAt (i )-'A' ]--;
48
+ }
49
+ }
50
+
51
+ // 1. 기준이 되는 문자열보다 길이가 한 글자 작은 경우
52
+ if (len - 1 == comp .length () && cnt == comp .length ()) {
53
+ ans ++;
54
+ }else if (len == comp .length ()) { // 2. 기준이 되는 문자열보다 길이가 같을 경우
55
+ if (cnt == len || cnt == len - 1 ) {
56
+ ans ++;
57
+ }
58
+ }else if (len + 1 == comp .length ()) { // 3. 기준이 되는 문자열보다 길이가 한 글자 큰 경우
59
+ if (cnt == len ) {
60
+ ans ++;
61
+ }
62
+ }
63
+ }
64
+
65
+ // 정답을 출력
66
+ System .out .println (ans );
67
+
68
+ // bufferedReader 종료
69
+ br .close ();
70
+
71
+ }
72
+
73
+ }
You can’t perform that action at this time.
0 commit comments