[프로그래머스] 크기가 작은 부분 문자열 - c++

삼식이·2025년 5월 18일
0

알고리즘

목록 보기
56/81

크기가 작은 부분 문자열

이 문제는 히든케이스에서 안돌아갔는데, 알고보니 p의 길이 ≤ t의 길이 ≤ 10,000 이므로

부분문자열이 클 경우 stoi()를 못쓰고 long long형으로 변환하는 stoll()을 써야 처리가 가능했다.

#include <string>
#include <vector>
#include <iostream>

using namespace std;

int solution(string t, string p) {
    int answer = 0;
    int ss = t.size()-p.size();
    for(int i=0; i<=ss; i++) {
        string now = t.substr(i, p.size());
        if (stoll(now) <= stoll(p)) answer++;
    }
    return answer;
}

0개의 댓글