添加 'util.hpp'
This commit is contained in:
parent
d3633911a0
commit
7dc1739ac7
218
util.hpp
Normal file
218
util.hpp
Normal file
@ -0,0 +1,218 @@
|
||||
/// Part of BigData Project. Included By Main.cpp .
|
||||
/// This file should not be included by other files.
|
||||
|
||||
/// 薪资空间,平均值 单位:元,月薪
|
||||
struct cash_pack
|
||||
{
|
||||
int low,high;
|
||||
|
||||
int ave() const {return (low+high)/2;}
|
||||
};
|
||||
|
||||
/// 为map设计的比较算法
|
||||
bool operator < (const cash_pack& a,const cash_pack& b)
|
||||
{
|
||||
if(a.low==b.low)
|
||||
{
|
||||
return a.high<b.high;
|
||||
}
|
||||
else return a.low<b.low;
|
||||
}
|
||||
|
||||
/// 解析薪资空间信息
|
||||
cash_pack ParseCash(const char* ptr)
|
||||
{
|
||||
cash_pack pk;
|
||||
|
||||
auto strange=[&]()
|
||||
{
|
||||
cout<<"Strange: "<<ptr<<endl;
|
||||
system("pause");
|
||||
};
|
||||
|
||||
char* p=strstr(ptr,"-");
|
||||
if(p==nullptr)
|
||||
{
|
||||
if( strstr(ptr,"以上")!=nullptr || strstr(ptr,"以下")!=nullptr)
|
||||
{
|
||||
int t;
|
||||
sscanf(ptr,"%d",&t);
|
||||
pk.low=pk.high=t*1000;
|
||||
}
|
||||
else
|
||||
{
|
||||
strange();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
int alow,ahigh;
|
||||
sscanf(ptr,"%d",&alow);
|
||||
sscanf(p+1,"%d",&ahigh);
|
||||
pk.low=alow*1000;
|
||||
pk.high=ahigh*1000;
|
||||
}
|
||||
|
||||
return pk;
|
||||
}
|
||||
|
||||
cash_pack ParseCashX(const char* ptr)
|
||||
{
|
||||
cash_pack pk;
|
||||
|
||||
auto strange=[&]()
|
||||
{
|
||||
cout<<"Strange: "<<ptr<<endl;
|
||||
system("pause");
|
||||
};
|
||||
|
||||
char* p=strstr(ptr,"-");
|
||||
if(p==nullptr)
|
||||
{
|
||||
/// 此处由bigdata5数据库直接得出结论,谨慎使用!
|
||||
/// 单位:元/天 -> [ x30 ] 转换到 -> 元/月 , low=high
|
||||
int c;
|
||||
sscanf(ptr,"%d",&c);
|
||||
pk.low=pk.high=c*30;
|
||||
}
|
||||
else
|
||||
{
|
||||
double dlow,dhigh;
|
||||
sscanf(ptr,"%lf",&dlow);
|
||||
sscanf(p+1,"%lf",&dhigh);
|
||||
|
||||
/// 解析单位
|
||||
if(strstr(ptr,"千")!=nullptr||strstr(ptr,"k")!=nullptr||strstr(ptr,"K")!=nullptr)
|
||||
{
|
||||
dlow*=1000;
|
||||
dhigh*=1000;
|
||||
}
|
||||
else if(strstr(ptr,"万")!=nullptr)
|
||||
{
|
||||
dlow*=10000;
|
||||
dhigh*=10000;
|
||||
}
|
||||
else if(strstr(ptr,"元")!=nullptr)
|
||||
{
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
cout<<"strange: 单位错误"<<endl;
|
||||
strange();
|
||||
}
|
||||
|
||||
/// 解析日期单位
|
||||
if(strstr(ptr,"天")!=nullptr)
|
||||
{
|
||||
pk.low=dlow*30;
|
||||
pk.high=dhigh*30;
|
||||
}
|
||||
else if(strstr(ptr,"月")!=nullptr)
|
||||
{
|
||||
pk.low=dlow;
|
||||
pk.high=dhigh;
|
||||
}
|
||||
else if(strstr(ptr,"年")!=nullptr)
|
||||
{
|
||||
pk.low=dlow/12;
|
||||
pk.high=dhigh/12;
|
||||
}
|
||||
else
|
||||
{
|
||||
if(strstr(ptr,"/")==nullptr)
|
||||
{
|
||||
/// 默认情况月薪
|
||||
pk.low=dlow;
|
||||
pk.high=dhigh;
|
||||
}
|
||||
else
|
||||
{
|
||||
cout<<"strange: 时间单位错误"<<endl;
|
||||
strange();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return pk;
|
||||
}
|
||||
|
||||
/// 解析tag
|
||||
vector<string> ParseTag(const char* str)
|
||||
{
|
||||
vector<string> vec;
|
||||
|
||||
char* s=(char*)str;
|
||||
char* p=nullptr;
|
||||
char buff[256];
|
||||
while(nullptr!=
|
||||
(p=strstr(s,","))
|
||||
)
|
||||
{
|
||||
memset(buff,0,256);
|
||||
strncpy(buff,s,p-s);
|
||||
vec.push_back(string(buff));
|
||||
s=p+1;
|
||||
}
|
||||
|
||||
int len=strlen(str);
|
||||
if(s<str+len)
|
||||
{
|
||||
memset(buff,0,256);
|
||||
strcpy(buff,s);
|
||||
vec.push_back(string(buff));
|
||||
}
|
||||
|
||||
return vec;
|
||||
}
|
||||
|
||||
/// 解析int
|
||||
int ParseInt(const char* str)
|
||||
{
|
||||
int cc;
|
||||
sscanf(str,"%d",&cc);
|
||||
return cc;
|
||||
}
|
||||
|
||||
string Trim(const string& str)
|
||||
{
|
||||
int sz=str.size();
|
||||
int L=-1;
|
||||
int R=-1;
|
||||
for(int i=0;i<sz;i++)
|
||||
{
|
||||
if(str[i]==' '||str[i]=='\t'||str[i]=='\n'||str[i]=='\r')
|
||||
{
|
||||
continue;
|
||||
}
|
||||
else
|
||||
{
|
||||
L=i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(L==-1)
|
||||
{
|
||||
/// All characters are [Space].
|
||||
return "";
|
||||
}
|
||||
for(int i=sz-1;i>=0;--i)
|
||||
{
|
||||
if(str[i]==' '||str[i]=='\t'||str[i]=='\n'||str[i]=='\r')
|
||||
{
|
||||
continue;
|
||||
}
|
||||
else
|
||||
{
|
||||
R=i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(R==-1)
|
||||
{
|
||||
/// All characters are [Space]/
|
||||
return "";
|
||||
}
|
||||
|
||||
return str.substr(L,R-L+1);
|
||||
}
|
Reference in New Issue
Block a user