- 코드
정답 코드 : 처음 P의 길이만큼 넣고 같지않을때 같을때까지의 문자열의 길이 -1을 빼줘서 copy개수를 맞춤. 그 다음 i가 p의길이만큼 됐을때가 처리가 안되서 추가시켜주엇다.
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class Main {
public static void main(String[] args) throws IOException {
// TODO Auto-generated method stub
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String S = br.readLine();
String P = br.readLine();
String temp="";
int count=P.length();
for(int i=0;i<P.length();i++) {
temp+=P.charAt(i);
if(i==P.length()-1 && S.contains(temp))
count-=temp.length()-1;
if(!S.contains(temp)) {
if(temp.length()>2)
count-=temp.length()-2;
temp=P.charAt(i)+"";
}
}
System.out.println(count);
}
}
'algorithm' 카테고리의 다른 글
[JAVA] 백준 3745번 : 오름세 (0) | 2020.09.07 |
---|---|
[JAVA] 백준 13398번 : 연속합 2 (0) | 2020.09.04 |
[JAVA] 백준 11401번 : 이항 계수 3 (0) | 2020.09.03 |
[JAVA] 백준 1300번 : K 번째 수 (0) | 2020.09.02 |
[JAVA] 백준 15666번 : N과 M (12) (0) | 2020.09.02 |