• 코드

정답 코드 : 처음 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);
	}
}

+ Recent posts