728x90
반응형
해커랭크(HackerRank) - The Grid Search // C++
https://www.hackerrank.com/challenges/the-grid-search/problem
string gridSearch(vector<string> G, vector<string> P) {
int gridRow = G.size();
int gridCol = G[0].length();
int patternRow = P.size();
int patternCol = P[0].length();
for(int j = 0 ;j<gridRow-patternRow+1;j++)
{
for(int i = 0;i<gridCol-patternCol+1;i++)
{
if(
memcmp((const char*)&(G[j].c_str()[i]),
(const char*)P[0].c_str(),
patternCol )==0
)
{
int matchCount = 1;
for(int k =1 ;k<patternRow;k++)
{
if(
memcmp((const char*)&(G[j+k].c_str()[i]),
(const char*)P[k].c_str(),
patternCol )==0
){
matchCount++;
}else
break;
}
if(matchCount ==patternRow )
{
return "YES";
}
}
}
}
return "NO";
}
728x90
반응형
'개발 > 코딩' 카테고리의 다른 글
백준 - 설탕 배달 - Swift (0) | 2022.07.10 |
---|---|
해커랭크(HackerRank) - Almost Sorted // C++ (0) | 2021.05.19 |
[hackerrank] Minimum Absolute Difference in an Array / C++ (0) | 2020.12.07 |
LeetCode - Two Sum / c++ (0) | 2020.07.24 |
해커랭크(HackerRank) - Closest Numbers / C++ (0) | 2020.07.11 |
댓글