https://www.acmicpc.net/problem/11478
11478번: 서로 다른 부분 문자열의 개수
첫째 줄에 문자열 S가 주어진다. S는 알파벳 소문자로만 이루어져 있고, 길이는 1,000 이하이다.
www.acmicpc.net

HashMap을 Value 값을 계속해서 덮어서 썼다.
import java.io.*;
import java.util.*;
public class Main {
public static void main(String[] args) throws Exception {
BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
String str = bf.readLine();
HashMap<String, Integer>map = new HashMap<String, Integer>();
int index = 0;
int length = 1;
while (true) {
if (index + length > str.length()) {
index = 0;
length++;
}
if (length <= str.length()) {
} else {
break;
}
String strTemp = str.substring(index, index + length);
index++;
map.put(strTemp, 1);
}
System.out.println(map.size());
}
}
'Java' 카테고리의 다른 글
| [백준] 2993번 : 세 부분 (0) | 2023.03.07 |
|---|---|
| [백준] 9996번 : 한국이 그리울 땐 서버에 접속하지 (0) | 2023.03.01 |
| [백준] 11899번 : 괄호 끼워넣기 (0) | 2023.02.28 |
| 추상클래스와 인터페이스 차이 (1) | 2023.02.15 |
| 자바 연습하기(일기) (0) | 2023.01.26 |