BOJ 1543 문서검색
-
변수
String S; //전체 문자열 String compare_s; //비교할 문자열
-
로직
-
전체 문자열에서 비교할 문자열을 indexOf로 찾는다.(가장 앞에것이 리턴)
-
전체 문자열에서 그 부분을 자른다.
-
해당 행동을 반복한다.
-
-
코드
package com.ssafy;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class BOJ_1543_문서검색_210119 {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String S = br.readLine();
String compare_s = br.readLine();
int cnt = 0;
while (true) {
int index = S.indexOf(compare_s);
if (index == -1)
break;
S = S.substring(index + compare_s.length());
cnt++;
}
System.out.println(cnt);
}
}
Leave a comment