fork download
  1. #include <stdio.h>
  2. #include <vector>
  3.  
  4. const char digitset[] = "123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
  5.  
  6. void allocate_to_groups_impl( std::vector<char>& usage, std::vector<int>& order, const std::vector<int>& cumsum, int group, int place, int min )
  7. {
  8. if (place == cumsum[group]) {
  9. group++; min = 0;
  10. if (group == cumsum.size()) {
  11. for( std::vector<int>::iterator it = order.begin(); it != order.end(); ++it )
  12. putchar(digitset[*it]);
  13. putchar('\n');
  14. return;
  15. }
  16. }
  17.  
  18. for( int v = min, max = usage.size() + place - cumsum[group]; v <= max; ++v ) {
  19. if (!usage[v]) {
  20. order[place] = v;
  21. usage[v] = 1;
  22. allocate_to_groups_impl(usage, order, cumsum, group, place+1, v+1);
  23. usage[v] = 0;
  24. }
  25. }
  26. }
  27.  
  28. template<size_t Ngroups>
  29. void allocate_to_groups( int (&c)[Ngroups] )
  30. {
  31. size_t sum_of_c = 0;
  32. std::vector<int> cumsum_of_c;
  33. for( int it = c; it < c + Ngroups; ++it )
  34. cumsum_of_c.push_back(sum_of_c += *it);
  35. std::vector<int> order(sum_of_c);
  36. std::vector<char> usage(sum_of_c);
  37.  
  38. allocate_to_groups_impl(usage, order, cumsum_of_c, 0, 0, 0);
  39. }
  40.  
  41. int main(void)
  42. {
  43. int c[] = { 2, 3, 2 };
  44. allocate_to_groups(c);
  45. };
Compilation error #stdin compilation error #stdout 0s 2960KB
stdin
Standard input is empty
compilation info
prog.cpp: In function 'void allocate_to_groups(int (&)[Ngroups])':
prog.cpp:34:44: error: invalid type argument of unary '*'
prog.cpp: In function 'void allocate_to_groups(int (&)[Ngroups]) [with unsigned int Ngroups = 3u]':
prog.cpp:44:25:   instantiated from here
prog.cpp:33:19: error: invalid conversion from 'int*' to 'int'
prog.cpp:33:19: error: ISO C++ forbids comparison between pointer and integer
stdout
Standard output is empty