https://school.programmers.co.kr/learn/courses/30/lessons/147355
일단 p의 길이가 최대 18이므로 int는 벗어나므로 double을 사용
p를 stod로 double로 변환
for문을 돌리면서 p의 길이만큼을 stod로 double로 변환 한 뒤 값이 작은지 비교한다.
#include <string>
#include <vector>
using namespace std;
int solution(string t, string p) {
int answer = 0;
double pnum = stod(p);
double tnum;
for(int i = 0; i <= t.length() - p.length(); i++)
{
tnum = stod(t.substr(i, p.length()));
if(tnum <= pnum)
answer++;
}
return answer;
}
#include <bits/stdc++.h>
using namespace std;
int solution(string t, string p)
{
int answer = 0;
int length = p.length();
long long int intP = stoll(p);
for (int i = 0; i <= t.length() - length; ++i)
{
string number = t.substr(i, length);
long long int intNumber = stoll(number);
if (intNumber <= intP)
{
++answer;
}
}
return answer;
}
double대신 longlong int를 사용