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());	
	}
}

 

+ Recent posts