Advertisement
Guest User

Untitled

a guest
Oct 22nd, 2016
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.58 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. void combination(const char *str, int start, int end, int m, char *cmb, int m_exist){
  5. if(m==0){
  6. cout<<"{";
  7. for(int i=m_exist-1; i>0; i--)
  8. cout<<cmb[i]<<", ";
  9. cout<<cmb[0]<<"}"<<endl;
  10.  
  11. return;
  12. }
  13.  
  14. for(int i=start; i<end; i++){
  15. cmb[m-1]=str[i];
  16. combination(str,i+1,end,m-1,cmb,m_exist);
  17. }
  18.  
  19. }
  20. int main() {
  21. string str("12345");
  22.  
  23. int N=str.size();
  24. int M=2; //change M whatever you want
  25.  
  26. char *cmb=new char[M];
  27.  
  28. combination(str.c_str(), 0, N, M, cmb, M);
  29.  
  30. delete [] cmb;
  31.  
  32. return 0;
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement