
indexOf 메서드를 사용하여 word가 document 내에서 발견될 때마다 반복적으로 찾고 substring을 사용하여 발견된 단어 이후의 문자열로 document를 재설정하였다.
시간복잡도: O(N²), 공간복잡도: O(N)
import java.util.*;
import java.io.*;
class Main {
public static void main (String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String document = br.readLine();
String word = br.readLine();
int count = 0;
int index = 0;
while(document.indexOf(word,index) != -1){
count++;
document = document.substring(document.indexOf(word) + word.length(), document.length());
}
System.out.println(count);
}
}
