fork download
  1. #include <iostream>
  2. #include <vector>
  3. using namespace std;
  4.  
  5. vector<int> res;
  6.  
  7. void helper(pair<int,int>& interval) {
  8. int start=interval.first;
  9. int end=interval.second;
  10. vector<int> ans;
  11.  
  12. for(int i=0; i<res.size(); i++) {
  13. for(int j=start; j<=end; j++) {
  14. ans.push_back(res[i]*10+j);
  15. }
  16. }
  17.  
  18. res=ans;
  19. }
  20.  
  21. vector<int> generatePermutation(vector<pair<int,int>>& intervals) {
  22. if(intervals.empty()) return res;
  23.  
  24. pair<int, int> firstInt=intervals[0];
  25. for(int i=firstInt.first; i<=firstInt.second; i++) {
  26. res.push_back(i);
  27. }
  28.  
  29. for(int i=1; i<intervals.size(); i++) {
  30. helper(intervals[i]);
  31. }
  32.  
  33. return res;
  34. }
  35.  
  36.  
  37. int main() {
  38. vector<pair<int,int>> v;
  39. v.push_back({2,6});
  40. v.push_back({4,5});
  41. v.push_back({1,5});
  42.  
  43. vector<int> ans=generatePermutation(v);
  44.  
  45. for(auto& each: ans) cout<<each<<" ";
  46.  
  47. return 0;
  48. }
Success #stdin #stdout 0.01s 5536KB
stdin
Standard input is empty
stdout
241 242 243 244 245 251 252 253 254 255 341 342 343 344 345 351 352 353 354 355 441 442 443 444 445 451 452 453 454 455 541 542 543 544 545 551 552 553 554 555 641 642 643 644 645 651 652 653 654 655