본문 바로가기

Algorithm_BOJ(백준)/문자열

[백준 16916 c++ V] 부분 문자열

728x90
반응형

- 풀이 링크:

https://github.com/xhaktmchl/Algorithm_study/blob/main/BOJ/%EB%AC%B8%EC%9E%90%EC%97%B4/%5B%EB%B0%B1%EC%A4%80%2016916%20c%2B%2B%20V%5D%20%EB%B6%80%EB%B6%84%20%EB%AC%B8%EC%9E%90%EC%97%B4%20.cpp

 

GitHub - xhaktmchl/Algorithm_study: 알고리즘 이론 및 문제풀이

알고리즘 이론 및 문제풀이. Contribute to xhaktmchl/Algorithm_study development by creating an account on GitHub.

github.com

#include <iostream>
#include <algorithm>
//#include <map> // 중복 x 
#include <string> // getline
#include <cstring> // memset, strok, strstr
//#include <vector>
//#include <queue>
//#include <set> // 트리, 중복 x
//#include <unordered_set>
using namespace std;
/*
[백준 16916 c++ V] 부분 문자열 
접근1: 
시간복잡도: n
풀이: 
    //1.입력
    //2.s문자열 탐색: 해당 문자부터 p문자열포함했는지
    //3.출력
*/
string s, p;

int main()
{
    ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(0);
    
    //1.입력
    cin >> s >> p;
    //2.s문자열 탐색: 해당 문자부터 p문자열포함했는지
    if (strstr((char*)s.c_str(), (char*)p.c_str()) == NULL) {
        cout << 0 << '\n';
    }
    else cout << 1 << '\n';
    //3.출력
    return 0;
}
반응형