09-29 03:12
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | 6 | 7 |
8 | 9 | 10 | 11 | 12 | 13 | 14 |
15 | 16 | 17 | 18 | 19 | 20 | 21 |
22 | 23 | 24 | 25 | 26 | 27 | 28 |
29 | 30 |
Tags
- Entity Set
- Polymolphism
- X.org
- Binary Search
- Inheritance
- 자바
- Entity
- literal
- Reference Type
- python
- BFS
- preprocessing
- 리눅스
- X윈도우
- dbms
- 셀레니움
- 리눅스 기초
- 백준
- Mac
- Physical Scheme
- OOP
- Operator
- Class
- Unity
- systemd
- selenium
- zsh
- Java
- External Scheme
- 리눅스 마스터 1급
Archives
- Today
- Total
Byeol Lo
N1305 - 광고 본문
import java.io.InputStreamReader;
import java.io.BufferedReader;
import java.io.IOException;
public class N1305 {
private static final BufferedReader BR = new BufferedReader(new InputStreamReader(System.in));
static String paragraph;
static int n;
public static void main(String[] args) throws IOException{
n = Integer.parseInt(BR.readLine());
paragraph = BR.readLine();
System.out.print(n - getFailureScores(paragraph)[n-1]);
}
static int[] getFailureScores(String pattern) {
int[] table = new int[pattern.length()];
int j = 0;
for (int i = 1; i < table.length; i++) {
while (j > 0 && pattern.charAt(j) != pattern.charAt(i))
j = table[j-1];
if (pattern.charAt(i) == pattern.charAt(j))
table[i] = ++j;
}
return table;
}
}
'Algorithm > KMP' 카테고리의 다른 글
N1786 - 찾기 (0) | 2024.05.11 |
---|---|
N11585 - 속타는 저녁 메뉴 (0) | 2024.05.08 |
Comments