代码如下 | 复制代码 |
#include #include #include usingnamespacestd; struct_AREA_VECTOR_STRUCT { intnAreaType;//区域类型 intnAreaID;//区域ID };
voidCtestDlg::OnBnClickedButton2() { vector<_area_vector_struct>structAreaHistory;//车辆上一次所在区域 vector<_area_vector_struct>structAreaNow;//车辆本次所在区域 vector<_area_vector_struct>OutStructAreaVector;//输出区域
_AREA_VECTOR_STRUCT structVehicle;
//模拟上一次车辆所在的区域集合 structVehicle.nAreaType = 2; structVehicle.nAreaID = 0x45; structAreaHistory.push_back(structVehicle); structVehicle.nAreaID = 0x7A; structAreaHistory.push_back(structVehicle); structVehicle.nAreaID = 0x88; structAreaHistory.push_back(structVehicle);
structVehicle.nAreaType = 3; structVehicle.nAreaID = 0x55; structAreaHistory.push_back(structVehicle); structVehicle.nAreaID = 0x88; structAreaHistory.push_back(structVehicle);
//模拟本次车辆所在的区域集合 structVehicle.nAreaType = 2; structVehicle.nAreaID = 0x88; structAreaNow.push_back(structVehicle); structVehicle.nAreaID = 0x45; structAreaNow.push_back(structVehicle); structVehicle.nAreaID = 0x11; structAreaNow.push_back(structVehicle);
structVehicle.nAreaType = 3; structVehicle.nAreaID = 0x55; structAreaNow.push_back(structVehicle);
//排序,先按区域类型排序,再按区域ID排序 sort(structAreaHistory.begin(), structAreaHistory.end(),[] (_AREA_VECTOR_STRUCT structArea1, _AREA_VECTOR_STRUCT structArea2)->bool { if(structArea1.nAreaType != structArea2.nAreaType) returnstructArea1.nAreaType < structArea2.nAreaType; else returnstructArea1.nAreaID < structArea2.nAreaID; }); sort(structAreaNow.begin(), structAreaNow.end(),[] (_AREA_VECTOR_STRUCT structArea1, _AREA_VECTOR_STRUCT structArea2)->bool { if(structArea1.nAreaType != structArea2.nAreaType) returnstructArea1.nAreaType < structArea2.nAreaType; else returnstructArea1.nAreaID < structArea2.nAreaID; });
inta = 0;
//求差,结果为离开区域的集合(出区域) set_difference(structAreaHistory.begin(), structAreaHistory.end(), structAreaNow.begin(), structAreaNow.end(), back_inserter(OutStructAreaVector), [](_AREA_VECTOR_STRUCT structArea1, _AREA_VECTOR_STRUCT structArea2)->bool { if(structArea1.nAreaType != structArea2.nAreaType) returnstructArea1.nAreaType < structArea2.nAreaType; else returnstructArea1.nAreaID < structArea2.nAreaID; });
if(OutStructAreaVector.size() != 0) { TRACE("出"); }
OutStructAreaVector.clear();//先清空
//反过来求差,结果为新进入的区域集合(新进区域) set_difference(structAreaNow.begin(), structAreaNow.end(), structAreaHistory.begin(), structAreaHistory.end(), back_inserter(OutStructAreaVector), [](_AREA_VECTOR_STRUCT structArea1, _AREA_VECTOR_STRUCT structArea2)->bool { if(structArea1.nAreaType != structArea2.nAreaType) returnstructArea1.nAreaType < structArea2.nAreaType; else returnstructArea1.nAreaID < structArea2.nAreaID;
});
if(OutStructAreaVector.size() != 0) { TRACE("重新进"); } } |
迷你世界越南服 安卓版v1.7.15
迷你世界越南服是一款精美的3D沙盒游戏,拥有极高的创作自由度
糖饼外传内置菜单 安卓版v1.0.87
糖饼外传内置菜单是一款非常好玩的模拟经营类手游,玩家在游戏中
我的世界化学交换空岛整合包 最新版v1.0
我的世界化学交换空岛整合包是一款像素风格的沙盒生存游戏,游戏
创造厨房免广告版 v1.0.10
创造厨房无广告版是一款像素风模拟经营类手游,玩家们将在这里化
SimCity BuildIt无限金币版 安卓修改版v1.60.1.133743
SimCity BuildIt无限金币版是经过破解的版本,在