#include <iostream>
#include<stdio.h>
#include <list>
using namespace std;
list<string> subList(list<string> list1, int s, int e);
int main() {
list<string> source;
source.emplace_back("0");
source.emplace_back("1");
source.emplace_back("1");
source.emplace_back("0");
int n = 2;
list<list<string>> result;
int remainder = source.size() % n; //先计算出余数
int number = source.size() / n; //然后是商
int offset = 0;//偏移量(用以标识加的余数)
for (int i = 0; i < n; i++) {
list<string> value;
if (remainder > 0) {
int s = i * number + offset;
int e = (i + 1) * number + offset + 1;
value = subList(source, s, e);
remainder--;
offset++;
} else {
int s = i * number + offset;
int e = (i + 1) * number + offset;
value = subList(source, s, e);
}
result.emplace_back(value);
}
return 0;
}
list<string> subList(list<string> list1, int start, int end) {
list<string> source;
auto it = list1.begin();
bool is = false;
for (int i = 0; i < list1.size(); ++i) {
string name = *it;
if (i == start) {
is = true;
}
if (i == end) {
break;
}
if (is) {
source.emplace_back(name);
}
it++;
}
return source;
}
找了这么多结果没一个c++分配任务的算法,还得自己写一个,分享给大家复制粘贴