Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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
- 백준
- 1편
- 코테
- 중반부
- BFS
- Algorithm
- Smilegate
- 카카오
- 알고리즘
- 투포인터
- 유니온파인드
- LIS #Algorithm #요소추적
- 소감
- 스마일게이트
- c++
- BaekJoon
- 코딩테스트
- IBK기업은행 #기업은행 #디지털 #직무 #정리
- 식단
- 서버개발캠프
- 삼성 #코테 #2020상반기 #c++
- 카카오인턴
- Union-find
- 보석쇼핑
Archives
- Today
- Total
짱아의 개발 기록장
백준 1701번. Cubeditor(c++) / kmp 본문
반응형
전형적인 kmp문제이다.
하지만 더 추가해야할 포인트가 있다.
입력받은 문자열에 대한 failure function을 작성해서 돌리되,
kmp Algorithm은 맨 처음 문자부터 시작하기 때문에 접미사를 하나씩 지우면서 최대값을 찾아나갔다.
일단, kmp Algorithm에 대한 개념이 생소하신 분은 아래 링크를 참고해서 공부하시면 될 것 같습니다.
https://jason9319.tistory.com/130
KMP(Knuth–Morris–Pratt) 알고리즘
KMP 알고리즘은 문자열 A와 문자열 B가 있을 때, 문자열 A에서 문자열 B를 찾아주는 알고리즘 입니다. KMP는 KMP를 만든 사람의 이름인 Knuth, Morris, Prett 세 사람의 앞 글자를 따서 KMP 알고리즘이라고 �
jason9319.tistory.com
코드 첨부
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
31
32
33
34
35
36
37
38
|
// Cubeditor
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
string s, temp;
int final = 0;
vector<int> getPi(string p){//실패 함수 작성
int m = (int)p.size(), j=0;
vector<int> pi(m, 0);
for(int i = 1; i< m ; i++){
while(j > 0 && p[i] != p[j])
j = pi[j-1];
if(p[i] == p[j])
pi[i] = ++j;
}
return pi;
}
int main()
{
cin>>s;
temp = s;
for (int i=0; i < s.size(); i++) {
string temp = s.substr(i, s.size());
auto matched = getPi(temp);
for (int j=0; j <matched.size(); j++) {
final = max(final, matched[j]);
}
}
cout<<final<<"\n";
return 0;
}
|
cs |
github 첨부
https://github.com/jungahshin/algorithm/blob/master/c:c%2B%2B/1701.cpp
jungahshin/algorithm
algorithm study. Contribute to jungahshin/algorithm development by creating an account on GitHub.
github.com
반응형
'Algorithm > Baekjoon' 카테고리의 다른 글
백준 16197번. 두 동전(c++) / bfs (0) | 2020.07.31 |
---|---|
백준 16924번. 십자가 찾기(c++) / 시뮬레이션 (0) | 2020.07.29 |
백준 1593번. 문자 해독(c++) / 문자열 처리 (0) | 2020.07.24 |
백준 17398번. 통신망 분할(c++) / union-find (0) | 2020.07.23 |
백준 1890번. 점프(c++) / DP (0) | 2020.07.22 |
Comments