c++利用stlset_difference对车辆进出区域进行判定-创新互联

核心代码

阿瓦提ssl适用于网站、小程序/APP、API接口等需要进行数据传输应用场景,ssl证书未来市场广阔!成为创新互联建站的ssl证书销售渠道,可以享受市场价格4-6折优惠!如果有意向欢迎电话联系或者加微信:028-86922220(备注:SSL证书合作)期待与您的合作!
#include   
#include   
#include   
#include   
using namespace std;  
struct _AREA_VECTOR_STRUCT 
{ 
  int nAreaType;//区域类型 
  int nAreaID;//区域ID 
}; 
 
void CtestDlg::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) 
      return structArea1.nAreaType < structArea2.nAreaType; 
    else 
      return structArea1.nAreaID < structArea2.nAreaID; 
  }); 
  sort(structAreaNow.begin(), structAreaNow.end(),[] (_AREA_VECTOR_STRUCT structArea1, _AREA_VECTOR_STRUCT structArea2)->bool 
  { 
    if(structArea1.nAreaType != structArea2.nAreaType) 
      return structArea1.nAreaType < structArea2.nAreaType; 
    else 
      return structArea1.nAreaID < structArea2.nAreaID; 
  }); 
 
  int a = 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) 
      return structArea1.nAreaType < structArea2.nAreaType; 
    else 
      return structArea1.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) 
      return structArea1.nAreaType < structArea2.nAreaType; 
    else 
      return structArea1.nAreaID < structArea2.nAreaID; 
   
  }); 
 
  if(OutStructAreaVector.size() != 0) 
  { 
    TRACE("重新进"); 
  } 
}

另外有需要云服务器可以了解下创新互联建站www.cdcxhl.com,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。


网站题目:c++利用stlset_difference对车辆进出区域进行判定-创新互联
分享链接:http://scyanting.com/article/ccjioo.html