본문 바로가기

Algorithm_BOJ(백준)/문자열

[백준 16171 c++ O] 나는 친구가 적다 (Small)

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%2016171%20c%2B%2B%20O%5D%20%EB%82%98%EB%8A%94%20%EC%B9%9C%EA%B5%AC%EA%B0%80%20%EC%A0%81%EB%8B%A4%20(Small).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;
/*
[백준 16171 c++ O] 나는 친구가 적다 (Small)
접근1: 문자열 구현
시간복잡도: nlogn
풀이: 
    //1.입력
    //2.문자열에서 숫자 제거
    //3.문자 포함되었는지 탐색
    //4.출력
*/
string a, b, c;

int main()
{
    ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(0);
    
    //1.입력
    cin >> a >> b;
    //2.문자열에서 숫자 제거
    int size = a.size();
    for (int i = 0; i < size; i++) {
        if (a[i] >= '0' && a[i] <= '9') continue;
        c.push_back(a[i]);
    }
    //3.문자 포함되었는지 탐색
    //4.출력
    if (c.find(b) == string::npos) cout << 0 << '\n';
    else cout << 1 << '\n';
    return 0;
}
반응형