Header
#include <stdio.h>
#include <iostream>
#include <string>
#include <string.h>
#include <vector>
using namespace std;
class SearchWord
{
public:
SearchWord();
SearchWord( wstring, wstring );
~SearchWord();
private:
vector<bool> vBool;
wstring txt = L"";
wstring word = L"";
size_t szWord = 0;
int nWordIndex = 0;
int nTxtIndex = 0;
int nSearchCount = 0;
private:
bool check();
public:
int isEqaul();
public:
int getCount(){ return this->nSearchCount; }
};
CPP
#include "Test.h"
using namespace std;
SearchWord::SearchWord( wstring rWord, wstring rTxt )
: word( rWord ), txt( rTxt ), szWord( rWord.size() )
{
for (int i = 0; i < szWord; i++)
{
vBool.push_back( false );
}
}
SearchWord::~SearchWord(){}
bool SearchWord::check()
{
for( int i = 0; i < szWord; i++ )
{
if (vBool.at( i ) == false) return false;
}
return true;
}
int SearchWord::isEqaul()
{
if ( nTxtIndex > txt.size() -1 ) return -1;
if (this->txt.at( nTxtIndex ) == this->word.at( nWordIndex ))
{
vBool.at( nWordIndex ) = true;
nTxtIndex++;
if( nWordIndex >= szWord - 1)
{
if (check() == true) nSearchCount++;
for (int i = 0; i < szWord; i++)
{
vBool.at( i ) = false;
}
nWordIndex = 0;
}
else nWordIndex++;
isEqaul();
}
else
{
vBool.at( nWordIndex ) = false;
nTxtIndex++;
nWordIndex = 0;
isEqaul();
}
}
string::find 쓰면 편하긴 할텐데..
'Programming > C & C++' 카테고리의 다른 글
Visual Studio 2017 - E1696 cannot open source file "###" (0) | 2020.02.06 |
---|---|
Visual Studio 2005 TaskList 토큰 추가 적용이 안 될 때 (0) | 2019.09.26 |
Visual Studio - An exception has been encountered this may be caused by an extension. (0) | 2019.04.21 |
operator overloading (0) | 2019.03.29 |
문자열 수식을 입력받아 계산하기 (0) | 2019.02.27 |