vector 排序与匹配

vector 排序与匹配


#include <algorithm>

// 判断是否
bool actionMatch(const std::string& strBegin, const std::string& strInput, std::string & strTail)
{
	bool bResult = (strInput.size() >= strBegin.size())
		&& equal(strBegin.begin(), strBegin.end(), strInput.begin());

	if (bResult)
	{
		int iPos = strInput.compare(strInput);
		strTail = strInput.substr(iPos);
	}
	return bResult;
}

// 匹配比较结构
typedef struct 
{
	std::string m_szLabel;
	void* m_pAction;
}DActionInfo;

// 比较字符串
bool sortActionInfo(const DActionInfo& a, const DActionInfo& b)
{
	if (a.m_szLabel > b.m_szLabel)
	{
		return true;
	}
	else
	{
		return false;
	}
}

void test_sort()
{
	// 填充输入
	std::vector<std::string> arrInput;

	// 填充命令
	std::vector<DActionInfo> arrMatch;
	arrMatch.push_back({ "ab", (void*)0 });
	arrMatch.push_back({ "ac", (void*)1 });
	arrMatch.push_back({ "abc", (void*)2 });
	arrMatch.push_back({ "bc", (void*)3 });
	arrMatch.push_back({ "ad", (void*)4 });

	// 排序
	std::sort(arrMatch.begin(), arrMatch.end(), sortActionInfo);

	// 匹配
	for (int i = 0; i< arrMatch.size();i++)
	{
		for (int j = 0; j < arrInput.size(); j++)
		{
			std::string strTail = "";
			if (actionMatch(arrMatch.at(i).m_szLabel, arrInput.at(j), strTail ))
			{
				// 匹配成功, 退出当前循环

				break;
			}
		}
		
	}

	return;
}


int main()
{
	test_sort();
	return 0;



	CsvFile csv;
	csv.loadFromFile("G:\\tmp\\testdata.csv");

	s32 iRowCount = csv.getRowCount();
	for(s32 i = 0; i < iRowCount; i++)
	{
		std::vector<std::string> *data = csv.getRow(i);
		for (auto cell : *data)
		{
			printf("%s  ", cell.c_str());
		}
		printf("\n");
	}

	return 0;
}

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值