Advertisement
Pabon_SEC

The Hamming Distance Problem

May 2nd, 2016
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.58 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. char str[20];
  6.  
  7. int main()
  8. {
  9.     int test,i,n,h;
  10.  
  11.     scanf("%d",&test);
  12.  
  13.     while(test--)
  14.     {
  15.         scanf("%d%d",&n,&h);
  16.  
  17.         for(i=0;i<n-h;i++)
  18.         {
  19.             str[i] = '0';
  20.         }
  21.  
  22.         for(i=n-h;i<n;i++)
  23.         {
  24.             str[i] = '1';
  25.         }
  26.  
  27.         str[n] = '\0';
  28.  
  29.         printf("%s\n",str);
  30.  
  31.         while(next_permutation(str,str+n))
  32.         {
  33.             printf("%s\n",str);
  34.         }
  35.  
  36.         if(test)
  37.         {
  38.             puts("");
  39.         }
  40.     }
  41.  
  42.     return 0;
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement