Code: Select all
int main(int argc, char* argv[]) {
int nBins;
str2Num(argv[1], nBins);
std::vector<int> rk;
int total = 0;
int nPerBin = 0;
for (int i = 2; i < argc; i++) {
int tmp;
str2Num(argv[i], tmp);
rk.push_back(tmp);
total += tmp;
}
nPerBin = total / nBins;
const int T = rk.size();
for (int b = 0; b < nBins; b++) {
int nSelect = (b < nBins - 1) ? nPerBin : total;
int nSelectFrom = total;
for (int t = 0; t < T; t++) {
int tmp = (int)rhyper(rk[t], nSelectFrom-rk[t], nSelect);
cout << setw(10) << tmp;
nSelect -= tmp;
nSelectFrom -= rk[t];
rk[t] -= tmp;
total -= tmp;
}
cout << endl;
}
}
Code: Select all
$ ./test 11 1000 2000 3000 4000 5000 6000
90 166 297 363 417 576
105 187 253 399 457 508
84 192 295 363 449 526
73 193 267 359 463 554
108 177 275 355 440 554
93 173 241 381 452 569
99 173 267 395 449 526
89 191 250 355 464 560
84 196 276 361 465 527
82 164 281 343 492 547
93 188 298 326 452 553