문자열 찾기2 [python] String(문자열) 포함 여부 확인 안녕하세요. TDR입니다. 오늘은 python에서 어떤 string에 내가 찾고자 하는 string이 포함되어 있는지 확인 방법에 대해서 간략히 정리해 볼까 합니다. 찾고자 하는 string 포함이 되어 있는가? ## 'hello'가 포함되어 있는지 확인 # in print('hello' in 'Hi and hello~') # True print('test' in 'Hi and hello~') # False # find result = 'Hi and hello~'.find('hello') print(result) # 7 result = 'Hi and hello~'.find('test') print(result) # -1 # index result = 'Hi and hello~'.index('hello').. 2024. 3. 14. KMP 알고리즘... #include #include #include #include using namespace std; class KMP { private : char array[200], pat[10]; // array는 비교할 문자열, pat는 찾을 문자열 int temp; // 비교할 문자의 실패함수의 현재 값 int f_pat[10]; int i, k; // 함수 제어의 필요한 함수 int n, l; // n은 찾을 문자열의 길이 l은 비교할 문자열의 길이 public : KMP() { temp=-1, i=0, k=0; for(i=0; i input(); } void KMP::makefaile() { int val=0, p=0; // val은 실패함수에 들어갈 값이고 p는 함수 제어 변수이다. int j=1, i;.. 2009. 3. 4. 이전 1 다음