https://school.programmers.co.kr/learn/courses/30/lessons/120908
a에 str2의 크기 만큼 str1의 원소를 하나하나 추가한다음 str2와 같은지 비교
#include <string>
#include <vector>
using namespace std;
int solution(string str1, string str2) {
int answer = 2;
for(int i = 0; i < str1.size()-2; i++)
{
string a = "";
for(int j = 0; j < str2.size(); j++)
{
a += str1[i+j];
}
if(a == str2)
{
answer = 1;
break;
}
}
return answer;
}
#include <string>
#include <vector>
using namespace std;
int solution(string str1, string str2) {
return (str1.find(str2) == string::npos)?2:1;
}
find쓰면 매우 쉽게끝남 string::npos는 find해서 없으면 반환하는 값 (-1)