[문자열-strstr] 부분 문자열 - 백준 16916번
char *strstr(const char *string1, const char *string2);
- input1 :
char *string1
- input2 :
char *string2
- output type :
char *
- string 말고 char *로
const int MAX_LENGTH = 1000001;
- 최대 길이 + 1
Reference : https://www.ibm.com/docs/ko/i/7.3?topic=functions-strstr-locate-substring
코드
#include <iostream>
#include <cstring>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
// 입력 받을 문자열의 최대 길이 지정
const int MAX_LENGTH = 1000001;
char plain_text[MAX_LENGTH];
char target[MAX_LENGTH];
cin >> plain_text >> target;
const char* result = strstr(plain_text, target);
if (result != nullptr) {
cout << 1 << endl;
// cout << "찾은 문자열: " << result << endl;
} else {
cout << 0 << endl;
// cout << "문자열을 찾을 수 없습니다." << endl;
}
return 0;
}