C++에서 string의 find() 함수를 사용하여 문자열 내에서 특정 문자를 찾을 때, 찾는 문자열이 존재하지 않으면 find()는 string::npos를 반환한다. 이 값을 이용해 검색 실패 여부를 판단할 수 있다.
#include <string>
#include <vector>
using namespace std;
int solution(vector<string> spell, vector<string> dic) {
int answer = 2;
for(string s: dic) {
int cnt = 0;
for(string k: spell) {
if (s.find(k) == string::npos) continue;
cnt++;
}
if (cnt == spell.size()) {
return 1;
}
}
return answer;
}