Advertisement
mateuspl

combinacao

Apr 14th, 2016
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.49 KB | None | 0 0
  1. #include <iostream>
  2. #include <sstream>
  3.  
  4. using namespace std;
  5.  
  6. int SIZE = 0;
  7.  
  8. void pnums(int size, int from, int to, string curr)
  9. {
  10.     if (size == 0)
  11.     {
  12.         //cout << curr << endl;
  13.         SIZE++;
  14.     }
  15.     else
  16.     {
  17.         for (int i = from; i <= to; i++)
  18.         {
  19.             ostringstream conv; conv << curr << i << " ";
  20.             pnums(size - 1, i + 1, to, conv.str());
  21.         }
  22.     }
  23. }
  24.  
  25. int  main()
  26. {
  27.     int size, from, to;
  28.     cin >> size >> from >> to;
  29.     pnums(size, from, to, "");
  30.     cout << endl << SIZE << endl;
  31.     return 0;
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement