#include <iostream>
#include <unordered_map>
#include <string>
using namespace std;
unsigned int JSHash(const char* str)
{
unsigned int hash = 1315423911;
while (*str)
{
hash ^= ((hash << 5) + (*str++) + (hash >> 2));
}
return (hash & 0x7FFFFFFF);
}
int choosePolise(unsigned int custId)
{
double cp = (JSHash(to_string(unsigned (custId)).c_str()) % 200 + 1) / 200.0;
//cout << cp << endl;
int number = 0;
double policies_ratio[] = { 0.2,0.2,0.2,0.2,0.2 };
//double policies_ratio[] = { 0.33,0.33,0.34 };
//double policies_ratio[] = { 0.25,0.25,0.25,0.25 };
//double policies_ratio[] = { 0.5,0.5 };
//double policies_ratio[] = { 0.15,0.15,0.15,0.25,0.15,0.15 };
int policy_num = 5 ;
while (number < policy_num && (policies_ratio[number] - cp) < 0.0001)
{
cp = cp - policies_ratio[number];
if (number == policy_num - 1)
break;
number++;
}
cout << to_string(custId) + " ### " + to_string(cp) + " ### " + to_string(number) << endl;
return number;
}
int main() {
int custId;
//int custIdList[13] = {1800910528,1710766244,1234590337,1553283882,1165445462,1557052348,1557052349,1524244103,1520001269,1511291164,1802090458,1801999148,1803350941 };
for ( int i = 1808781239; i <= 1808781248; i++)
{
custId = i;
cout << custId << endl;
int police = choosePolise(custId);
}
return 0;
}
分组样例代码
于 2023-11-28 11:16:21 首次发布